-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.h
More file actions
88 lines (69 loc) · 1.87 KB
/
commands.h
File metadata and controls
88 lines (69 loc) · 1.87 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
#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include "dir.h"
#include "usage.h"
#include <pthread.h>
#include <netinet/in.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <time.h>
#include <dirent.h>
#define MAXDATASIZE 256
enum FTP_CMD {
INVALID = -1,
USER = 1,
PASS = 2,
RETR = 3,
PASV = 4,
TYPE = 5,
QUIT = 6,
CWD = 7,
CDUP = 8,
MODE = 9,
STRU = 10,
NLST = 11,
SYST = 12
};
struct ftp_cmd {
enum FTP_CMD cmd;
char* args;
};
// Keep track of the state of the server constantly
struct State {
int loggedIn;
char* rootDir;
int newPasvFD;
int currentPasvFD;
int pasvHasBeenCalled;
};
struct State* state;
struct ftp_cmd* parse_cmd(char buf[]);
// call the accept system command to accept the socket connection from the server side.
// @return the FD of the new socket
int accept_connection(struct sockaddr_storage* their_addr, int sockfd);
// Create the socket given the port, and store the value of the new FD into sockfd
void create_socket(int* sockfd, char* port);
// For all the following functions, we handle the client message with the arg,
// and write the correct server code and message to server_message.
// @return nothing
void login(char* arg, char server_message[]);
void type(char* arg, char server_message[]);
void mode(char* arg, char server_message[]);
void stru(char* arg, char server_message[]);
void cwd(char* rootDir, char* arg, char server_message[]);
void cdup(char* rootDir, char* arg, char server_message[]);
void pasv(char server_message[], int new_fd);
void nlst(char* arg, char server_message[]);
void retr(char* arg, char server_message[]);