-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcmd.h
More file actions
120 lines (94 loc) · 3.26 KB
/
cmd.h
File metadata and controls
120 lines (94 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* Copyright (C) 2023 John Törnblom
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */
#pragma once
#include <limits.h>
#include <netinet/in.h>
#include <unistd.h>
/**
* Data structure that captures the current state of a client.
**/
typedef struct ftp_env {
int data_fd;
int active_fd;
int passive_fd;
char cwd[PATH_MAX];
char type;
int self2elf;
off_t data_offset;
char rename_path[PATH_MAX];
struct sockaddr_in data_addr;
void *readbuf;
size_t readbuf_size;
} ftp_env_t;
/**
* Callback function prototype for ftp commands.
**/
typedef int (ftp_command_fn_t)(ftp_env_t* env, const char* arg);
/**
* Standard FTP commands.
**/
int ftp_cmd_APPE(ftp_env_t *env, const char* arg);
int ftp_cmd_CDUP(ftp_env_t *env, const char* arg);
int ftp_cmd_CWD (ftp_env_t *env, const char* arg);
int ftp_cmd_DELE(ftp_env_t *env, const char* arg);
int ftp_cmd_FEAT(ftp_env_t *env, const char* arg);
int ftp_cmd_LIST(ftp_env_t *env, const char* arg);
int ftp_cmd_MKD (ftp_env_t *env, const char* arg);
int ftp_cmd_MLSD(ftp_env_t *env, const char* arg);
int ftp_cmd_NOOP(ftp_env_t *env, const char* arg);
int ftp_cmd_PASV(ftp_env_t *env, const char* arg);
int ftp_cmd_PORT(ftp_env_t *env, const char* arg);
int ftp_cmd_PWD (ftp_env_t *env, const char* arg);
int ftp_cmd_QUIT(ftp_env_t *env, const char* arg);
int ftp_cmd_REST(ftp_env_t *env, const char* arg);
int ftp_cmd_RETR(ftp_env_t *env, const char* arg);
int ftp_cmd_RMD (ftp_env_t *env, const char* arg);
int ftp_cmd_RNFR(ftp_env_t *env, const char* arg);
int ftp_cmd_RNTO(ftp_env_t *env, const char* arg);
int ftp_cmd_SIZE(ftp_env_t *env, const char* arg);
int ftp_cmd_STOR(ftp_env_t *env, const char* arg);
int ftp_cmd_SYST(ftp_env_t *env, const char* arg);
int ftp_cmd_TYPE(ftp_env_t *env, const char* arg);
int ftp_cmd_USER(ftp_env_t *env, const char* arg);
/**
* Custom FTP commands.
**/
int ftp_cmd_KILL(ftp_env_t *env, const char* arg);
int ftp_cmd_MTRW(ftp_env_t *env, const char* arg);
int ftp_cmd_CHMOD(ftp_env_t *env, const char* arg);
int ftp_cmd_SELF(ftp_env_t *env, const char* arg);
/**
* Error responses to unknown/unavailable FTP commands.
**/
int ftp_cmd_unavailable(ftp_env_t *env, const char* arg);
int ftp_cmd_unknown(ftp_env_t *env, const char* arg);
/**
* Transmit a formatted string via an active connection.
**/
int ftp_active_printf(ftp_env_t *env, const char *fmt, ...);
/**
* Resolve a path to its absolute path.
**/
void ftp_abspath(ftp_env_t *env, char *abspath, const char *path);
/**
* Transmit an errno string via an active connection.
**/
int ftp_perror(ftp_env_t *env);
/**
* Open a new FTP data connection.
**/
int ftp_data_open(ftp_env_t *env);
/**
* Close an existing data connection.
**/
int ftp_data_close(ftp_env_t *env);