retrieve
[oftp] / src / ftp.h
1 #ifndef FTP_H_
2 #define FTP_H_
3
4 #include <stdio.h>
5
6 enum {FTP_DIR, FTP_FILE};       /* ftp_dirent type */
7
8 enum {
9         FTP_TYPE,
10         FTP_PWD,
11         FTP_CHDIR,
12         FTP_CDUP,
13         FTP_MKDIR,
14         FTP_RMDIR,
15         FTP_DEL,
16         FTP_LIST,
17         FTP_RETR,
18         FTP_STORE,
19         FTP_XFER
20 };
21
22 enum {
23         FTP_DISC,
24         FTP_CONN_PASV,
25         FTP_CONN_ACT
26 };
27
28 enum {
29         FTP_MOD_DIR     = 0x100
30 };
31
32 struct ftp_op {
33         int op;
34         char *arg;
35         void *data;
36
37         struct ftp_op *next;
38 };
39
40 struct ftp_dirent {
41         char *name;
42         int type;
43         long size;
44 };
45
46 struct ftp {
47         int ctl, lis, data;     /* sockets */
48         int lis_port;
49
50         int status, busy;
51         char *user, *pass;
52         int passive;
53
54         struct ftp_op *qhead, *qtail;
55
56         int (*cproc)(struct ftp *ftp, int code, const char *buf, void *cls);
57         void (*dproc)(struct ftp *ftp, const char *buf, int sz, void *cls);
58         void *cproc_cls, *dproc_cls;
59
60         char crecv[256];
61         int num_crecv;
62         char drecv[256];
63
64         char *curdir;
65         struct ftp_dirent *dirent;              /* dynamic array */
66
67         int last_resp;
68         int modified;
69 };
70
71 struct ftp_transfer {
72         int op;
73         char *rname;
74         FILE *fp;               /* option: file */
75         char *mem;              /* option: darray */
76         long total, count;
77
78         void (*done)(struct ftp*, struct ftp_transfer*);
79 };
80
81 struct ftp *ftp_alloc(void);
82 void ftp_free(struct ftp *ftp);
83
84 void ftp_auth(const char *user, const char *pass);
85
86 int ftp_connect(struct ftp *ftp, const char *host, int port);
87 void ftp_close(struct ftp *ftp);
88
89 int ftp_sockets(struct ftp *ftp, int *sockv, int maxsize);
90
91 int ftp_handle(struct ftp *ftp, int s);
92
93 int ftp_queue(struct ftp *ftp, int op, const char *arg);
94 int ftp_queue_transfer(struct ftp *ftp, struct ftp_transfer *xfer);
95 int ftp_waitresp(struct ftp *ftp, long timeout);
96
97 int ftp_update(struct ftp *ftp);
98 int ftp_type(struct ftp *ftp, const char *type);
99 int ftp_pwd(struct ftp *ftp);
100 int ftp_chdir(struct ftp *ftp, const char *dirname);
101 int ftp_mkdir(struct ftp *ftp, const char *dirname);
102 int ftp_rmdir(struct ftp *ftp, const char *dirname);
103 int ftp_delete(struct ftp *ftp, const char *fname);
104 int ftp_list(struct ftp *ftp);
105 int ftp_retrieve(struct ftp *ftp, const char *fname);
106 int ftp_store(struct ftp *ftp, const char *fname);
107 int ftp_transfer(struct ftp *ftp, struct ftp_transfer *xfer);
108
109 const char *ftp_curdir(struct ftp *ftp);
110 int ftp_num_dirent(struct ftp *ftp);
111 struct ftp_dirent *ftp_dirent(struct ftp *ftp, int idx);
112
113 int ftp_direntcmp(const void *a, const void *b);
114
115 #endif  /* FTP_H_ */