Added missing file (again).
[uftps.git] / uftps.h
blob9df9b430ac9433d1da2101bd67ae52032a023835
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>
31 /* Attributes help to catch silly mistakes, but they are not always available */
32 #ifndef __GNUC__
33 # define __attribute__(x)
34 #endif
36 /* Constants */
37 #define DEFAULT_PORT 2211
38 #define LINE_SIZE 4096 /* Same value as PATH_MAX */
40 /* Recognized commands */
41 enum command
43 FTP_NONE = 0,
44 FTP_ABOR, FTP_ACCT, FTP_ALLO, FTP_APPE, FTP_CDUP, FTP_CWD, FTP_DELE,
45 FTP_FEAT, FTP_HELP, FTP_LIST, FTP_MDTM, FTP_MKD, FTP_MODE, FTP_NLST,
46 FTP_NOOP, FTP_OPTS, FTP_PASS, FTP_PASV, FTP_PORT, FTP_PWD, FTP_QUIT,
47 FTP_REIN, FTP_REST, FTP_RETR, FTP_RMD, FTP_RNFR, FTP_RNTO, FTP_SITE,
48 FTP_SIZE, FTP_SMNT, FTP_STAT, FTP_STOR, FTP_STOU, FTP_STRU, FTP_SYST,
49 FTP_TYPE, FTP_USER
52 /* Session (client) state */
53 struct _SessionScope
55 /* Sockets */
56 int control_sk; /* Control channel */
57 int data_sk; /* Data channel */
58 int passive_sk; /* Server socket for passive mode */
60 /* Buffer offsets and fill counters */
61 int input_offset; /* Input buffer data offset */
62 int input_len; /* Bytes in input buffer */
63 int passive_len; /* Length of passive reply */
64 int cwd_len; /* Length of current working directory */
66 /* Other state information */
67 int passive_mode; /* Passive mode flag */
68 off_t file_offset; /* Last REST offset accepted */
69 char *arg; /* Pointer to comand line argument */
71 /* Buffers */
72 char passive_str[32]; /* Cached reply for PASV */
73 char input[LINE_SIZE]; /* Incoming command buffer */
74 char aux[LINE_SIZE]; /* Auxiliary buffer */
75 char cwd[LINE_SIZE]; /* Current Working Directory */
78 extern struct _SessionScope SS; /* SS --> Session State */
81 * Logging functions. These functions are implemented in log.c
83 #ifdef DEBUG
84 # define assert(cond) if (!(cond)) warning("Assertion '" #cond "' failed")
85 void debug (const char *, ...) __attribute__((format(printf,1,2)));
86 #else
87 # define assert(cond)
88 static inline void debug (const char *msg, ...) {}
89 #endif
91 void notice (const char *, ...) __attribute__((format(printf,1,2)));
92 void warning (const char *, ...) __attribute__((format(printf,1,2)));
93 void error (const char *, ...) __attribute__((format(printf,1,2)));
94 void fatal (const char *, ...) __attribute__((format(printf,1,2), noreturn));
98 * Other functions. Each function declared here is implemented in a separate
99 * file, with the same name as the function. Functions sorted alphabetically.
101 int apply_path (const char *, char *, int);
102 void change_dir (void);
103 void client_port (void);
104 void command_loop (void);
105 int expand_arg (void);
106 void file_stats (int type);
107 void init_session (int cmd_sk);
108 void list_dir (int full_list);
109 enum command next_command (void);
110 void reply (const char *, int);
111 void send_file (void);
115 * Utility macro to call reply() with a constant string. At compile time, the
116 * length of these strings is known.
118 #define reply_c(str) reply(str, sizeof(str) - 1)