quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

ftp.h (7379B)


      1 #ifndef HEADER_CURL_FTP_H
      2 #define HEADER_CURL_FTP_H
      3 /***************************************************************************
      4  *                                  _   _ ____  _
      5  *  Project                     ___| | | |  _ \| |
      6  *                             / __| | | | |_) | |
      7  *                            | (__| |_| |  _ <| |___
      8  *                             \___|\___/|_| \_\_____|
      9  *
     10  * Copyright (C) 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 https://curl.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  * SPDX-License-Identifier: curl
     24  *
     25  ***************************************************************************/
     26 
     27 #include "curl_setup.h"
     28 
     29 #include "pingpong.h"
     30 
     31 #ifndef CURL_DISABLE_FTP
     32 extern const struct Curl_handler Curl_handler_ftp;
     33 
     34 #ifdef USE_SSL
     35 extern const struct Curl_handler Curl_handler_ftps;
     36 #endif
     37 
     38 CURLcode Curl_GetFTPResponse(struct Curl_easy *data, ssize_t *nread,
     39                              int *ftpcode);
     40 
     41 bool ftp_conns_match(struct connectdata *needle, struct connectdata *conn);
     42 
     43 #endif /* CURL_DISABLE_FTP */
     44 
     45 /****************************************************************************
     46  * FTP unique setup
     47  ***************************************************************************/
     48 enum {
     49   FTP_STOP,    /* do nothing state, stops the state machine */
     50   FTP_WAIT220, /* waiting for the initial 220 response immediately after
     51                   a connect */
     52   FTP_AUTH,
     53   FTP_USER,
     54   FTP_PASS,
     55   FTP_ACCT,
     56   FTP_PBSZ,
     57   FTP_PROT,
     58   FTP_CCC,
     59   FTP_PWD,
     60   FTP_SYST,
     61   FTP_NAMEFMT,
     62   FTP_QUOTE, /* waiting for a response to a command sent in a quote list */
     63   FTP_RETR_PREQUOTE,
     64   FTP_STOR_PREQUOTE,
     65   FTP_LIST_PREQUOTE,
     66   FTP_POSTQUOTE,
     67   FTP_CWD,  /* change dir */
     68   FTP_MKD,  /* if the dir did not exist */
     69   FTP_MDTM, /* to figure out the datestamp */
     70   FTP_TYPE, /* to set type when doing a head-like request */
     71   FTP_LIST_TYPE, /* set type when about to do a dir list */
     72   FTP_RETR_LIST_TYPE,
     73   FTP_RETR_TYPE, /* set type when about to RETR a file */
     74   FTP_STOR_TYPE, /* set type when about to STOR a file */
     75   FTP_SIZE, /* get the remote file's size for head-like request */
     76   FTP_RETR_SIZE, /* get the remote file's size for RETR */
     77   FTP_STOR_SIZE, /* get the size for STOR */
     78   FTP_REST, /* when used to check if the server supports it in head-like */
     79   FTP_RETR_REST, /* when asking for "resume" in for RETR */
     80   FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
     81   FTP_PRET, /* generic state for PRET RETR, PRET STOR and PRET LIST/NLST */
     82   FTP_PASV, /* generic state for PASV and EPSV, check count1 */
     83   FTP_LIST, /* generic state for LIST, NLST or a custom list command */
     84   FTP_RETR,
     85   FTP_STOR, /* generic state for STOR and APPE */
     86   FTP_QUIT,
     87   FTP_LAST  /* never used */
     88 };
     89 typedef unsigned char ftpstate; /* use the enum values */
     90 
     91 struct ftp_parselist_data; /* defined later in ftplistparser.c */
     92 
     93 struct ftp_wc {
     94   struct ftp_parselist_data *parser;
     95 
     96   struct {
     97     curl_write_callback write_function;
     98     FILE *file_descriptor;
     99   } backup;
    100 };
    101 
    102 typedef enum {
    103   FTPFILE_MULTICWD  = 1, /* as defined by RFC1738 */
    104   FTPFILE_NOCWD     = 2, /* use SIZE / RETR / STOR on the full path */
    105   FTPFILE_SINGLECWD = 3  /* make one CWD, then SIZE / RETR / STOR on the
    106                             file */
    107 } curl_ftpfile;
    108 
    109 /* This FTP struct is used in the Curl_easy. All FTP data that is
    110    connection-oriented must be in FTP_conn to properly deal with the fact that
    111    perhaps the Curl_easy is changed between the times the connection is
    112    used. */
    113 struct FTP {
    114   char *path;    /* points to the urlpieces struct field */
    115   char *pathalloc; /* if non-NULL a pointer to an allocated path */
    116 
    117   /* transfer a file/body or not, done as a typedefed enum just to make
    118      debuggers display the full symbol and not just the numerical value */
    119   curl_pp_transfer transfer;
    120   curl_off_t downloadsize;
    121 };
    122 
    123 
    124 /* ftp_conn is used for struct connection-oriented data in the connectdata
    125    struct */
    126 struct ftp_conn {
    127   struct pingpong pp;
    128   char *account;
    129   char *alternative_to_user;
    130   char *entrypath; /* the PWD reply when we logged on */
    131   char *file;    /* url-decoded filename (or path) */
    132   char **dirs;   /* realloc()ed array for path components */
    133   char *newhost; /* the (allocated) IP addr or hostname to connect the data
    134                     connection to */
    135   char *prevpath;   /* url-decoded conn->path from the previous transfer */
    136   char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
    137                         and others (A/I or zero) */
    138   curl_off_t retr_size_saved; /* Size of retrieved file saved */
    139   char *server_os;     /* The target server operating system. */
    140   curl_off_t known_filesize; /* file size is different from -1, if wildcard
    141                                 LIST parsing was done and wc_statemach set
    142                                 it */
    143   int dirdepth;  /* number of entries used in the 'dirs' array */
    144   int cwdcount;     /* number of CWD commands issued */
    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   unsigned short newport;  /* the port of 'newhost' to connect the data
    149                               connection to */
    150   ftpstate state; /* always use ftp.c:state() to change state! */
    151   ftpstate state_saved; /* transfer type saved to be reloaded after data
    152                            connection is established */
    153   unsigned char use_ssl;   /* if AUTH TLS is to be attempted etc, for FTP or
    154                               IMAP or POP3 or others! (type: curl_usessl)*/
    155   unsigned char ccc;       /* ccc level for this connection */
    156   BIT(ftp_trying_alternative);
    157   BIT(dont_check);  /* Set to TRUE to prevent the final (post-transfer)
    158                        file size and 226/250 status check. It should still
    159                        read the line, just ignore the result. */
    160   BIT(ctl_valid);   /* Tells Curl_ftp_quit() whether or not to do anything. If
    161                        the connection has timed out or been closed, this
    162                        should be FALSE when it gets to Curl_ftp_quit() */
    163   BIT(cwddone);     /* if it has been determined that the proper CWD combo
    164                        already has been done */
    165   BIT(cwdfail);     /* set TRUE if a CWD command fails, as then we must prevent
    166                        caching the current directory */
    167   BIT(wait_data_conn); /* this is set TRUE if data connection is waited */
    168   BIT(shutdown);    /* connection is being shutdown, e.g. QUIT */
    169 };
    170 
    171 /* meta key for storing `struct FTP` as easy meta data */
    172 #define CURL_META_FTP_EASY   "meta:proto:ftp:easy"
    173 /* meta key for storing `struct ftp_conn` as connection meta data */
    174 #define CURL_META_FTP_CONN   "meta:proto:ftp:conn"
    175 
    176 #define DEFAULT_ACCEPT_TIMEOUT   60000 /* milliseconds == one minute */
    177 
    178 #endif /* HEADER_CURL_FTP_H */