-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
36 lines (35 loc) · 1.23 KB
/
Copy pathutils.h
File metadata and controls
36 lines (35 loc) · 1.23 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
//
// Created by 邱俣涵 on 2021/10/20.
//
#ifndef SERVER_UTILS_H
#define SERVER_UTILS_H
#define MAX_DATA_SIZE 8196
#define MAX_MESSAGE_SIZE 1024
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <arpa/inet.h>
// User's States.
enum UserState{NOTLOGIN,WRONGUSER,REQPASS,LOGIN,PORTMODE,PASVMODE,REQRNFR};
typedef struct User{
int userNo;//The identifier assigned to the user, indicating the user's position in the array
enum UserState state;
int connfd;//Used for Message
struct sockaddr_in addr;//User's IP,used for PORT
int filefd;//used for File
FILE *fp;//Pointer of Opened File
pthread_t file_thread;//The thread used for file transfer
char dir[MAX_MESSAGE_SIZE];//User's workDir in FTP server.Can't end with '/' except the root. e.g. "/home"
char filename[MAX_MESSAGE_SIZE];//used for RNFR
}User;
int parse_ip(User *user, const char *sentence);
int connect_filefd(User *user, char *sentence);
int parse_dir(char *user_path_parsed, char *source, User *user);
int parse_arg(int argc, char **argv, int *port, char *root);//Parse the arg
int get_local_ip(char *buf);
#endif //SERVER_UTILS_H