summaryrefslogtreecommitdiff
path: root/usr.bin/ftp/ftp.h
blob: adc2f2b643c14ffd4eb17aec243ca6fb2a863321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*	$OpenBSD: ftp.h,v 1.2 2019/05/12 20:58:19 jasper Exp $ */

/*
 * Copyright (c) 2015 Sunil Nimmagadda <sunil@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>

#include <signal.h>
#include <stdarg.h>
#include <stdio.h>

#define	S_HTTP	0
#define S_FTP	1
#define S_FILE	2
#define S_HTTPS	3

#define TMPBUF_LEN	131072
#define	IMSG_OPEN	1

#define P_PRE	100
#define P_OK	200
#define P_INTER	300
#define N_TRANS	400
#define	N_PERM	500

#ifndef nitems
#define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
#endif

struct imsg;
struct imsgbuf;

struct url {
	int	 scheme;
	int	 ipliteral;
	char	*host;
	char	*port;
	char	*path;
	char	*basic_auth;

	char	*fname;
	int	 chunked;
};

/* cmd.c */
void	cmd(const char *, const char *, const char *);

/* main.c */
extern struct imsgbuf	 child_ibuf;
extern const char	*useragent;
extern int		 activemode, family, io_debug, verbose, progressmeter;
extern volatile sig_atomic_t interrupted;
extern FILE		*msgout;

/* file.c */
struct url	*file_request(struct imsgbuf *, struct url *, off_t *, off_t *);
void		 file_save(struct url *, FILE *, off_t *);

/* ftp.c */
void		 ftp_connect(struct url *, struct url *, int);
struct url	*ftp_get(struct url *, struct url *, off_t *, off_t *);
void		 ftp_quit(struct url *);
void		 ftp_save(struct url *, FILE *, off_t *);
int		 ftp_auth(FILE *, const char *, const char *);
int		 ftp_command(FILE *, const char *, ...)
		     __attribute__((__format__ (printf, 2, 3)))
		     __attribute__((__nonnull__ (2)));
int		 ftp_eprt(FILE *);
int		 ftp_epsv(FILE *);
int		 ftp_getline(char **, size_t *, int, FILE *);
int		 ftp_size(FILE *, const char *, off_t *, char **);

/* http.c */
void		 http_connect(struct url *, struct url *, int);
struct url	*http_get(struct url *, struct url *, off_t *, off_t *);
void		 http_close(struct url *);
void		 http_save(struct url *, FILE *, off_t *);
void		 https_init(char *);

/* progressmeter.c */
void	start_progress_meter(const char *, const char *, off_t, off_t *);
void	stop_progress_meter(void);

/* url.c */
int		 scheme_lookup(const char *);
void		 url_connect(struct url *, struct url *, int);
char		*url_encode(const char *);
void		 url_free(struct url *);
struct url	*url_parse(const char *);
struct url	*url_request(struct url *, struct url *, off_t *, off_t *);
void		 url_save(struct url *, FILE *, off_t *);
void		 url_close(struct url *);
char		*url_str(struct url *);
void	 	 log_request(const char *, struct url *, struct url *);

/* util.c */
int	connect_wait(int);
void	copy_file(FILE *, FILE *, off_t *);
int	tcp_connect(const char *, const char *, int);
int	fd_request(char *, int, off_t *);
int	read_message(struct imsgbuf *, struct imsg *);
void	send_message(struct imsgbuf *, int, uint32_t, void *, size_t, int);
void	log_info(const char *, ...)
	    __attribute__((__format__ (printf, 1, 2)))
	    __attribute__((__nonnull__ (1)));