1#ifndef HEADER_CURL_FTP_H
2#define HEADER_CURL_FTP_H
3/***************************************************************************
4 *                                  _   _ ____  _
5 *  Project                     ___| | | |  _ \| |
6 *                             / __| | | | |_) | |
7 *                            | (__| |_| |  _ <| |___
8 *                             \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at http://curl.haxx.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ***************************************************************************/
24
25#include "pingpong.h"
26
27#ifndef CURL_DISABLE_FTP
28extern const struct Curl_handler Curl_handler_ftp;
29
30#ifdef USE_SSL
31extern const struct Curl_handler Curl_handler_ftps;
32#endif
33
34CURLcode Curl_ftpsendf(struct connectdata *, const char *fmt, ...);
35CURLcode Curl_GetFTPResponse(ssize_t *nread, struct connectdata *conn,
36                             int *ftpcode);
37#endif /* CURL_DISABLE_FTP */
38
39/****************************************************************************
40 * FTP unique setup
41 ***************************************************************************/
42typedef enum {
43  FTP_STOP,    /* do nothing state, stops the state machine */
44  FTP_WAIT220, /* waiting for the initial 220 response immediately after
45                  a connect */
46  FTP_AUTH,
47  FTP_USER,
48  FTP_PASS,
49  FTP_ACCT,
50  FTP_PBSZ,
51  FTP_PROT,
52  FTP_CCC,
53  FTP_PWD,
54  FTP_SYST,
55  FTP_NAMEFMT,
56  FTP_QUOTE, /* waiting for a response to a command sent in a quote list */
57  FTP_RETR_PREQUOTE,
58  FTP_STOR_PREQUOTE,
59  FTP_POSTQUOTE,
60  FTP_CWD,  /* change dir */
61  FTP_MKD,  /* if the dir didn't exist */
62  FTP_MDTM, /* to figure out the datestamp */
63  FTP_TYPE, /* to set type when doing a head-like request */
64  FTP_LIST_TYPE, /* set type when about to do a dir list */
65  FTP_RETR_TYPE, /* set type when about to RETR a file */
66  FTP_STOR_TYPE, /* set type when about to STOR a file */
67  FTP_SIZE, /* get the remote file's size for head-like request */
68  FTP_RETR_SIZE, /* get the remote file's size for RETR */
69  FTP_STOR_SIZE, /* get the size for STOR */
70  FTP_REST, /* when used to check if the server supports it in head-like */
71  FTP_RETR_REST, /* when asking for "resume" in for RETR */
72  FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
73  FTP_PRET, /* generic state for PRET RETR, PRET STOR and PRET LIST/NLST */
74  FTP_PASV, /* generic state for PASV and EPSV, check count1 */
75  FTP_LIST, /* generic state for LIST, NLST or a custom list command */
76  FTP_RETR,
77  FTP_STOR, /* generic state for STOR and APPE */
78  FTP_QUIT,
79  FTP_LAST  /* never used */
80} ftpstate;
81
82struct ftp_parselist_data; /* defined later in ftplistparser.c */
83
84struct ftp_wc_tmpdata {
85  struct ftp_parselist_data *parser;
86
87  struct {
88    curl_write_callback write_function;
89    FILE *file_descriptor;
90  } backup;
91};
92
93typedef enum {
94  FTPFILE_MULTICWD  = 1, /* as defined by RFC1738 */
95  FTPFILE_NOCWD     = 2, /* use SIZE / RETR / STOR on the full path */
96  FTPFILE_SINGLECWD = 3  /* make one CWD, then SIZE / RETR / STOR on the
97                            file */
98} curl_ftpfile;
99
100typedef enum {
101  FTPTRANSFER_BODY, /* yes do transfer a body */
102  FTPTRANSFER_INFO, /* do still go through to get info/headers */
103  FTPTRANSFER_NONE, /* don't get anything and don't get info */
104  FTPTRANSFER_LAST  /* end of list marker, never used */
105} curl_ftptransfer;
106
107/* This FTP struct is used in the SessionHandle. All FTP data that is
108   connection-oriented must be in FTP_conn to properly deal with the fact that
109   perhaps the SessionHandle is changed between the times the connection is
110   used. */
111struct FTP {
112  curl_off_t *bytecountp;
113  char *user;    /* user name string */
114  char *passwd;  /* password string */
115
116  /* transfer a file/body or not, done as a typedefed enum just to make
117     debuggers display the full symbol and not just the numerical value */
118  curl_ftptransfer transfer;
119  curl_off_t downloadsize;
120};
121
122
123/* ftp_conn is used for struct connection-oriented data in the connectdata
124   struct */
125struct ftp_conn {
126  struct pingpong pp;
127  char *entrypath; /* the PWD reply when we logged on */
128  char **dirs;   /* realloc()ed array for path components */
129  int dirdepth;  /* number of entries used in the 'dirs' array */
130  int diralloc;  /* number of entries allocated for the 'dirs' array */
131  char *file;    /* decoded file */
132  bool dont_check;  /* Set to TRUE to prevent the final (post-transfer)
133                       file size and 226/250 status check. It should still
134                       read the line, just ignore the result. */
135  bool ctl_valid;   /* Tells Curl_ftp_quit() whether or not to do anything. If
136                       the connection has timed out or been closed, this
137                       should be FALSE when it gets to Curl_ftp_quit() */
138  bool cwddone;     /* if it has been determined that the proper CWD combo
139                       already has been done */
140  bool cwdfail;     /* set TRUE if a CWD command fails, as then we must prevent
141                       caching the current directory */
142  char *prevpath;   /* conn->path from the previous transfer */
143  char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
144                        and others (A/I or zero) */
145  int count1; /* general purpose counter for the state machine */
146  int count2; /* general purpose counter for the state machine */
147  int count3; /* general purpose counter for the state machine */
148  ftpstate state; /* always use ftp.c:state() to change state! */
149  char * server_os;     /* The target server operating system. */
150  curl_off_t known_filesize; /* file size is different from -1, if wildcard
151                                LIST parsing was done and wc_statemach set
152                                it */
153};
154
155#endif /* HEADER_CURL_FTP_H */
156