home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE-.1 / FTP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-22  |  10.0 KB  |  267 lines

  1. /*
  2.  * ftp.h : Definitions for the asynchronous FTP client
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 23 Apr 1993.
  5.  */
  6.  
  7. #ifndef _FTP_H
  8. #define _FTP_H_
  9.  
  10. #include <sys/types.h>
  11. #include <netinet/in.h>
  12.  
  13. #if NeedFunctionPrototypes
  14. struct _FtpContext;
  15. #endif
  16.  
  17. typedef void (*FtpCallbackProc)(
  18. #if NeedFunctionPrototypes
  19.     struct _FtpContext* ftpc
  20. #endif
  21. );
  22.  
  23. typedef void (*FtpTraceProc)(
  24. #if NeedFunctionPrototypes
  25.     struct _FtpContext* ftpc,
  26.     int who,        /* 0 => recvd, non-0 => sent */
  27.     char *text
  28. #endif
  29. );
  30.  
  31. typedef struct _FtpContext {
  32.     /* Connection parameters */
  33.     char *hostname;        /* hostname to contact */
  34.     unsigned short servport;    /* port of ftp service */
  35.     char **h_addr_list;        /* list of host addresses to try */
  36.     char **this_addr;        /* which address are we trying */
  37.     struct sockaddr_in saddr;    /* address of the control connection */
  38.     /* Connection state */
  39.     int state;            /* state of FTP process */
  40.     int iostate;        /* connecting, reading, writing, or ready */
  41.     int reply_state;        /* sub-state during reply parsing */
  42.     int saved_state;        /* saved sub-state during IAC parsing */
  43.     char *cmd;            /* pending part of cmd to send */
  44.     /* Control connection */
  45.     int    ctrl;            /* file descriptor of control connection */
  46.     int    retcode;        /* code of last reply */
  47.     int    tmpcode;        /* scratchpad for continuation lines */
  48.     char reply[BUFSIZ<<4];     /* text of last reply */
  49.     int reply_len;        /* length of reply (so far) */
  50.     /* User transfer params */
  51.     char *user;            /* usually anonymous */
  52.     char *pass;            /* usually user@host.dom */
  53.     char *cwd;            /* remote directory */
  54.     char *wd;            /* the part of cwd remaining to do */
  55.     char *local_dir;        /* directory for local files */
  56.     int    type;            /* current transfer mode */
  57.     int    stripcr;        /* 1 if want to remove CR from ASCII files */
  58.     int prompt;            /* 1 to prompt during transfers */
  59.     int filecmd;        /* FTP_GET or FTP_PUT */
  60.     char **files;        /* array of files to GET or PUT */
  61.     int num_files;        /* how many files */
  62.     int this_file;        /* which file are we working on */
  63.     int this_size;        /* how big is it (if we know) */
  64.     FtpTraceProc trace;        /* called to trace transactions */
  65.     FtpCallbackProc done;    /* called when connection finished */
  66.     FtpCallbackProc done1;    /* called when each file transfer finished */
  67.     /* Data connection */
  68.     int    port;            /* the socket on which we will acccept(2) */
  69.     int    data;            /* a data connection established */
  70.     int local_fd;        /* fd for local copy of file (read or write) */
  71.     int num_bytes;        /* bytes transferred this file */
  72. } FtpContext;
  73.  
  74. extern FtpContext *ftpNewContext(
  75. #if NeedFunctionPrototypes
  76.     char *hostname, char *user, char *pass, char *cwd, char *local_dir,
  77.     int type, int stripcr, int prompt,
  78.     int filecmd, char **files, int num_files,
  79.     FtpTraceProc trace, FtpCallbackProc done1, FtpCallbackProc done
  80. #endif
  81. );
  82.  
  83. extern void ftpStart(
  84. #if NeedFunctionPrototypes
  85.     FtpContext *ftpc
  86. #endif
  87. );
  88.  
  89. extern void ftpAbort(
  90. #if NeedFunctionPrototypes
  91.     FtpContext *ftpc
  92. #endif
  93. );
  94.  
  95. extern void ftpFreeContext(
  96. #if NeedFunctionPrototypes
  97.     FtpContext *ftpc
  98. #endif
  99. );
  100.  
  101. /*
  102.  * Filecmd codes
  103.  */
  104. #define FTP_GET 1
  105. #define FTP_PUT 2
  106.  
  107. /* Values for state field of FtpContext */
  108. #define FTPS_OPEN        10
  109. #define FTPS_CONNECT        11
  110. #define FTPS_CONNECTED        12
  111. #define FTPS_USER        13
  112. #define FTPS_PASS        14
  113. #define FTPS_CWD        15
  114. #define FTPS_TYPE        16
  115. #define FTPS_READY        17
  116. #define FTPS_PORT        18
  117. #define FTPS_GETPUT        19
  118. #define FTPS_TRANSFER        20
  119. #define FTPS_EOF        21
  120. #define FTPS_QUIT        22
  121. #define FTPS_ABORT        23
  122. #define FTPS_ABORT2        24
  123.  
  124. /* Values for reply_state field of FtpContext */
  125. #define FTPS_REPLY_CODE        101
  126. #define FTPS_REPLY_CONT        102
  127. #define FTPS_REPLY_LAST        103
  128. #define FTPS_REPLY_MORE        104
  129. #define FTPS_REPLY_CHCK        105
  130. #define FTPS_REPLY_IAC1        106
  131. #define FTPS_REPLY_IAC2        107
  132. #define FTPS_REPLY_IAC3        108
  133.  
  134. /*
  135.  * Telnet codes
  136.  */
  137. #ifndef NO_ARPA_H
  138. # include <arpa/ftp.h>
  139. # include <arpa/telnet.h>
  140. #else
  141.   /* <arpa/ftp.h>
  142. # define TYPE_A          1       /* ASCII */
  143. # define TYPE_E          2       /* EBCDIC */
  144. # define TYPE_I          3       /* image */
  145. # define TYPE_L          4       /* local byte size */
  146.   /* <arpa/telnet.h> */
  147. # define IAC     255             /* interpret as command: */
  148. # define DONT    254             /* you are not to use option */
  149. # define DO      253             /* please, you use option */
  150. # define WONT    252             /* I won't use option */
  151. # define WILL    251             /* I will use option */
  152. # define IP      244             /* interrupt process--permanently */
  153. # define DM      242             /* data mark--for connect. cleaning */
  154. #endif /* !NO_ARPA_H */
  155.  
  156. /*
  157.  * FTP reply codes, per RFC 959
  158.  */
  159.  
  160. /* First digit */
  161. #define FTP_REPLY_TYPE(X)    (X/100)
  162. #define FTP_REPLY_PRELIM(X)    (FTP_REPLY_TYPE(X) == 1) /* +ve preliminary  */
  163. #define FTP_REPLY_COMPLETE(X)    (FTP_REPLY_TYPE(X) == 2) /* +ve complete     */
  164. #define FTP_REPLY_CONTINUE(X)    (FTP_REPLY_TYPE(X) == 3) /* +ve intermediate */
  165. #define FTP_REPLY_TRANSIENT(X)    (FTP_REPLY_TYPE(X) == 4) /* -ve transient    */
  166. #define FTP_REPLY_ERROR(X)    (FTP_REPLY_TYPE(X) == 5) /* -ve permanent    */
  167. #define FTP_REPLY_OK(X)        (X < 400)
  168. #define FTP_REPLY_ERR(X)    (X >= 400)
  169.  
  170. /* Second digit */
  171. #define FTP_REPLY_FUNCTION(X)    ((X%100)/10)
  172. #define FTP_REPLY_SYNTAX(X)    (FTP_REPLY_FUNCTION(X) == 0) /* syntax       */
  173. #define FTP_REPLY_INFO(X)    (FTP_REPLY_FUNCTION(X) == 1) /* information  */
  174. #define FTP_REPLY_CONN(X)    (FTP_REPLY_FUNCTION(X) == 2) /* connections  */
  175. #define FTP_REPLY_AUTH(X)    (FTP_REPLY_FUNCTION(X) == 3) /*authentication*/
  176. #define FTP_REPLY_UNSPEC(X)    (FTP_REPLY_FUNCTION(X) == 4) /* unspecified  */
  177. #define FTP_REPLY_FILE(X)    (FTP_REPLY_FUNCTION(X) == 5) /* file system  */
  178.  
  179. /* Third digit */
  180. #define FTP_REPLY_SPECIFIC(X)    (X%10)
  181.  
  182. /* Reply Codes by Function Groups (comment text from RFC959) */
  183. #define FTP_COMMAND_OK        200 /* Command okay. */
  184. #define FTP_SYNTAX_ERROR    500 /* Syntax error, command unrecognized.
  185.                        This may include errors such as
  186.                        command line too long. */
  187. #define FTP_PARM_SYNTAX_ERROR    501 /* Syntax error in parameters or
  188.                        arguments. */
  189. #define FTP_CMD_NOT_NEEDED    202 /* Command not implemented, superfluous
  190.                        at this site. */
  191. #define FTP_CMD_NOT_IMPL    502 /* Command not implemented. */
  192. #define FTP_BAD_CMD_SEQ        503 /* Bad sequence of commands. */
  193. #define FTP_CMD_PARM_NOT_IMPL    504 /* Command not implemented for that
  194.                        parameter. */
  195.  
  196. #define FTP_RESTART_MARKER    110 /* Restart marker reply.
  197.                        In this case, the text is exact and not
  198.                        left to the particular implementation;
  199.                        it must read:
  200.                            MARK yyyy = mmmm
  201.                        Where yyyy is User-process data stream
  202.                        marker, and mmmm server's equivalent
  203.                        marker (note the spaces between markers
  204.                        and "="). */
  205. #define FTP_SYS_STATUS        211 /* System status, or system help reply. */
  206. #define FTP_DIR_STATUS        212 /* Directory status. */
  207. #define FTP_FILE_STATUS        213 /* File status. */
  208. #define FTP_HELP_MSG        214 /* Help message.
  209.                        On how to use the server or the meaning
  210.                        of a particular non-standard command.
  211.                        This reply is useful only to the human
  212.                        user. */
  213. #define FTP_SYS_NAME        215 /* NAME system type.
  214.                        Where NAME is an official system name
  215.                        from the list in the Assigned Numbers
  216.                        document. */
  217. #define FTP_SERVICE_RDY_TIME    120 /* Service ready in nnn minutes. */
  218. #define FTP_SERVICE_RDY_USER    220 /* Service ready for new user. */
  219. #define FTP_SERVICE_CLOSING     221 /* Service closing control connection.
  220.                        Logged out if appropriate. */
  221. #define FTP_SERVICE_UNAVAILABLE    421 /* Service not available, closing control
  222.                        connection. This may be a reply to any
  223.                        command if the service knows it must
  224.                        shut down. */
  225. #define FTP_TRANSFER_STARTING    125 /* Data connection already open; transfer
  226.                        starting. */
  227. #define FTP_DATA_OPEN        225 /* Data connection open; no transfer in
  228.                        progress. */
  229. #define FTP_DATA_FAILED        425 /* Can't open data connection. */
  230. #define FTP_DATA_CLOSE_OK    226 /* Closing data connection.
  231.                        Requested file action successful (for
  232.                        example, file transfer or file abort).*/
  233. #define FTP_DATA_CLOSE_ABORT    426 /* Connection closed; transfer aborted. */
  234. #define FTP_ENTERING_PASSIVE    227 /* Entering Passive Mode
  235.                        (h1,h2,h3,h4,p1,p2). */
  236.  
  237. #define FTP_LOGIN_OK        230 /* User logged in, proceed. */
  238. #define FTP_LOGIN_ERR        530 /* Not logged in. */
  239. #define FTP_LOGIN_NEED_PASSWD    331 /* User name okay, need password. */
  240. #define FTP_LOGIN_NEED_ACCT    332 /* Need account for login. */
  241. #define FTP_FILE_NEED_ACCT    532 /* Need account for storing files. */
  242.  
  243. #define FTP_DATACONN_OPEN    150 /* File status okay; about to open data
  244.                        connection. */
  245. #define FTP_FILE_ACTION_OK    250 /* Requested file action okay, completed.*/
  246. #define FTP_PATHNAME_CREATED    257 /* "PATHNAME" created. */
  247. #define FTP_FILE_ACTION_PENDING    350 /* Requested file action pending further
  248.                        information. */
  249. #define FTP_FILE_UNAVAILABLE    450 /* Requested file action not taken.
  250.                        File unavailable (e.g., file busy). */
  251. #define FTP_ACTION_NOT_TAKEN    550 /* Requested action not taken.
  252.                        File unavailable (e.g., file not found,
  253.                        no access). */
  254. #define FTP_ABORTED_LOCAL_ERR    451 /* Requested action aborted. Local error
  255.                        in processing. */
  256. #define FTP_ABORTED_PAGE_TYPE    551 /* Requested action aborted. Page type
  257.                        unknown. */
  258. #define FTP_INSUFFICIENT_SPACE    452 /* Requested action not taken.
  259.                        Insufficient storage space in system.*/
  260. #define FTP_EXCEEDED_ALLOCATION    552 /* Requested file action aborted.
  261.                        Exceeded storage allocation (for
  262.                        current directory or dataset). */
  263. #define FTP_BAD_FILENAME    553 /* Requested action not taken.
  264.                        File name not allowed. */
  265.  
  266. #endif /* !_FTP_H */
  267.