ftp.h
changeset 0 1d0ce1ebbc72
equal deleted inserted replaced
-1:000000000000 0:1d0ce1ebbc72
       
     1 /*
       
     2  * Copyright (c) 2015 Sunil Nimmagadda <sunil@openbsd.org>
       
     3  *
       
     4  * Permission to use, copy, modify, and distribute this software for any
       
     5  * purpose with or without fee is hereby granted, provided that the above
       
     6  * copyright notice and this permission notice appear in all copies.
       
     7  *
       
     8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
       
     9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
       
    10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
       
    11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
       
    12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
       
    13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
       
    14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
       
    15  */
       
    16 
       
    17 #ifndef	FTP_H
       
    18 #define	FTP_H
       
    19 
       
    20 #include <sys/types.h>
       
    21 
       
    22 #include <signal.h>
       
    23 #include <stdarg.h>
       
    24 
       
    25 #define	S_HTTP	0
       
    26 #define S_FTP	1
       
    27 #define S_FILE	2
       
    28 #define S_HTTPS	3
       
    29 
       
    30 #define TMPBUF_LEN	131072
       
    31 
       
    32 #define P_PRE	100
       
    33 #define P_OK	200
       
    34 #define P_INTER	300
       
    35 #define N_TRANS	400
       
    36 #define	N_PERM	500
       
    37 
       
    38 #ifndef nitems
       
    39 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
       
    40 #endif /* nitems */
       
    41 
       
    42 struct url {
       
    43 	int	 scheme;
       
    44 	int	 ip_literal;
       
    45 	char	*host;
       
    46 	char	*port;
       
    47 	char	*path;
       
    48 	char	*basic_auth;
       
    49 };
       
    50 
       
    51 /* main.c */
       
    52 extern volatile sig_atomic_t interrupted;
       
    53 extern struct url	*ftp_proxy, *http_proxy;
       
    54 extern const char	*useragent;
       
    55 extern char		*oarg;
       
    56 extern int		 activemode, family, io_debug, verbose, progressmeter;
       
    57 
       
    58 int		 fd_request(char *, int, off_t *);
       
    59 
       
    60 /* cmd.c */
       
    61 void		 cmd(const char *, const char *, const char *);
       
    62 
       
    63 /* file.c */
       
    64 struct url	*file_get(struct url *, off_t *, off_t *);
       
    65 void		 file_save(struct url *, FILE *, off_t *);
       
    66 
       
    67 /* ftp.c */
       
    68 void		 ftp_connect(struct url *, int);
       
    69 struct url	*ftp_get(struct url *, off_t *, off_t *);
       
    70 void		 ftp_close(struct url *);
       
    71 void		 ftp_save(struct url *, FILE *, off_t *);
       
    72 int		 ftp_auth(FILE *, const char *, const char *);
       
    73 int		 ftp_command(FILE *, const char *, ...)
       
    74 		     __attribute__((__format__ (printf, 2, 3)))
       
    75 		     __attribute__((__nonnull__ (2)));
       
    76 int		 ftp_eprt(FILE *);
       
    77 int		 ftp_epsv(FILE *);
       
    78 int		 ftp_getline(char **, size_t *, int, FILE *);
       
    79 int		 ftp_size(FILE *, const char *, off_t *, char **);
       
    80 
       
    81 /* http.c */
       
    82 void		 http_connect(struct url *, int);
       
    83 struct url	*http_get(struct url *, off_t *, off_t *);
       
    84 void		 http_close(struct url *);
       
    85 void		 http_save(struct url *, FILE *, off_t *);
       
    86 void		 https_init(char *);
       
    87 
       
    88 /* progressmeter.c */
       
    89 void		start_progress_meter(const char *, const char *, off_t, off_t *);
       
    90 void		stop_progress_meter(void);
       
    91 
       
    92 /* url.c */
       
    93 int		 url_scheme_lookup(const char *);
       
    94 void		 url_connect(struct url *, int);
       
    95 char		*url_encode(const char *);
       
    96 void		 url_free(struct url *);
       
    97 struct url	*xurl_parse(const char *);
       
    98 struct url	*url_parse(const char *);
       
    99 struct url	*url_request(struct url *, off_t *, off_t *);
       
   100 void		 url_save(struct url *, FILE *, off_t *);
       
   101 void		 url_close(struct url *);
       
   102 char		*url_str(struct url *);
       
   103 const char	*url_scheme_str(int);
       
   104 const char	*url_port_str(int);
       
   105 
       
   106 /* util.c */
       
   107 int		 connect_wait(int);
       
   108 void		 copy_file(FILE *, FILE *, off_t *);
       
   109 int		 tcp_connect(const char *, const char *, int);
       
   110 void		 log_request(const char *, struct url *, struct url *);
       
   111 void		 log_info(const char *, ...)
       
   112 		     __attribute__((__format__ (printf, 1, 2)))
       
   113 		     __attribute__((__nonnull__ (1)));
       
   114 
       
   115 #endif	/* FTP_H */