Renamed the sendfile RETR flavour to linux.
[uftps.git] / uftps.h
blobf2a89f217e642e8482033868ed657986f51d604f
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 * Common definitions.
24 /* Large file support */
25 #define _FILE_OFFSET_BITS 64
26 #define _LARGEFILE_SOURCE
27 #define _LARGEFILE64_SOURCE
29 #include <sys/types.h>
30 #include <netinet/in.h>
32 /* Attributes help to catch silly mistakes, but they are not always available */
33 #ifndef __GNUC__
34 # define __attribute__(x)
35 #endif
37 /* Constants */
38 #define DEFAULT_PORT 2211
39 #define LINE_SIZE 4096 /* Same value as PATH_MAX */
41 /* Recognized commands */
42 enum command
44 FTP_NONE = 0,
45 FTP_ABOR, FTP_ACCT, FTP_ALLO, FTP_APPE, FTP_CDUP, FTP_CWD, FTP_DELE,
46 FTP_FEAT, FTP_HELP, FTP_LIST, FTP_MDTM, FTP_MKD, FTP_MODE, FTP_NLST,
47 FTP_NOOP, FTP_OPTS, FTP_PASS, FTP_PASV, FTP_PORT, FTP_PWD, FTP_QUIT,
48 FTP_REIN, FTP_REST, FTP_RETR, FTP_RMD, FTP_RNFR, FTP_RNTO, FTP_SITE,
49 FTP_SIZE, FTP_SMNT, FTP_STAT, FTP_STOR, FTP_STOU, FTP_STRU, FTP_SYST,
50 FTP_TYPE, FTP_USER
53 /* Data channel modes */
54 enum data_mode
56 DEFAULT_MODE, /* RFC default, unimplemented/unsupported */
57 ACTIVE_MODE, /* Active mode enabled with PORT requests */
58 PASSIVE_MODE /* Passive mode enabled with PASV requests */
61 /* Session (client) state */
62 struct _SessionScope
64 /* Sockets */
65 int control_sk; /* Control channel */
66 int data_sk; /* Data channel */
67 int passive_sk; /* Server socket for passive mode */
69 /* Buffer offsets and fill counters */
70 int input_offset; /* Input buffer data offset */
71 int input_len; /* Bytes in input buffer */
72 int cwd_len; /* Length of current working directory */
74 /* Misc state information */
75 enum data_mode mode; /* Current data channel mode */
76 off_t file_offset; /* Last REST offset accepted */
77 char *arg; /* Pointer to comand line argument */
79 /* Session addresses */
80 struct sockaddr_in port_destination; /* Parsed PORT argument */
81 struct sockaddr_in local_address; /* Control local IP */
82 struct sockaddr_in client_address; /* Control peer IP */
84 /* Buffers */
85 char input[LINE_SIZE]; /* Incoming command buffer */
86 char aux[LINE_SIZE]; /* Auxiliary buffer */
87 char cwd[LINE_SIZE]; /* Current Working Directory */
90 extern struct _SessionScope SS; /* SS --> Session State */
94 * Logging functions. These functions are implemented in log.c
96 #ifdef DEBUG
97 # define assert(cond) if (!(cond)) warning("Assertion '" #cond "' failed")
98 void debug (const char *, ...) __attribute__((format(printf,1,2)));
99 #else
100 # define assert(cond)
101 static inline void debug (const char *msg, ...) {}
102 #endif
105 * These functions will be replaced by variadic macros when compilers other than
106 * GCC can be tested.
108 void notice (const char *, ...) __attribute__((format(printf,1,2)));
109 void warning (const char *, ...) __attribute__((format(printf,1,2)));
110 void error (const char *, ...) __attribute__((format(printf,1,2)));
111 void fatal (const char *, ...) __attribute__((format(printf,1,2), noreturn));
115 * Reply functions, used to send data over the control and data channels
116 * respectively. Implemented in reply.c.
118 void reply (const char *, int);
119 int data_reply (const char *, int);
123 * Other functions. Each function declared here is implemented in a separate
124 * file, with the same name as the function. Functions sorted alphabetically.
126 void change_dir (void);
127 void command_loop (void) __attribute__((noreturn));
128 void enable_passive (void);
129 int expand_arg (void);
130 void file_stats (int);
131 void init_session (int);
132 void list_dir (int);
133 enum command next_command (void);
134 int open_data_channel (void);
135 int open_file (off_t *);
136 void parse_port_argument (void);
137 void send_file (void);
141 * Utility macro to call reply() with a constant string. At compile time, the
142 * length of these strings is known.
144 #define reply_c(str) reply(str, sizeof(str) - 1)