1/*	$NetBSD: ftp_var.h,v 1.8 2007/08/06 04:33:23 lukem Exp $	*/
2/*	from	NetBSD: ftp_var.h,v 1.75 2007/07/22 05:02:50 lukem Exp	*/
3
4/*-
5 * Copyright (c) 1996-2007 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Luke Mewburn.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *	This product includes software developed by the NetBSD
22 *	Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 *    contributors may be used to endorse or promote products derived
25 *    from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * Copyright (c) 1985, 1989, 1993, 1994
42 *	The Regents of the University of California.  All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 *    notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 *    notice, this list of conditions and the following disclaimer in the
51 *    documentation and/or other materials provided with the distribution.
52 * 3. Neither the name of the University nor the names of its contributors
53 *    may be used to endorse or promote products derived from this software
54 *    without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 *
68 *	@(#)ftp_var.h	8.4 (Berkeley) 10/9/94
69 */
70
71/*
72 * Copyright (C) 1997 and 1998 WIDE Project.
73 * All rights reserved.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 *    notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 *    notice, this list of conditions and the following disclaimer in the
82 *    documentation and/or other materials provided with the distribution.
83 * 3. Neither the name of the project nor the names of its contributors
84 *    may be used to endorse or promote products derived from this software
85 *    without specific prior written permission.
86 *
87 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
88 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * SUCH DAMAGE.
98 */
99
100/*
101 * FTP global variables.
102 */
103
104#ifdef SMALL
105#undef	NO_EDITCOMPLETE
106#define	NO_EDITCOMPLETE
107#undef	NO_PROGRESS
108#define	NO_PROGRESS
109#endif
110
111#if 0	/* tnftp */
112
113#include <sys/param.h>
114
115#include <netinet/in.h>
116#include <arpa/inet.h>
117
118#include <poll.h>
119
120#include <setjmp.h>
121#include <stringlist.h>
122
123#endif	/* tnftp */
124
125#ifndef NO_EDITCOMPLETE
126#include <histedit.h>
127#endif /* !NO_EDITCOMPLETE */
128
129#include "extern.h"
130#include "progressbar.h"
131
132/*
133 * Format of command table.
134 */
135struct cmd {
136	char		*c_name;	/* name of command */
137	const char	*c_help;	/* help string */
138	char		c_bell;		/* give bell when command completes */
139	char		c_conn;		/* must be connected to use command */
140	char		c_proxy;	/* proxy server may execute */
141#ifndef NO_EDITCOMPLETE
142	const char	*c_complete;	/* context sensitive completion list */
143#endif /* !NO_EDITCOMPLETE */
144	void		(*c_handler)(int, char **); /* function to call */
145};
146
147/*
148 * Format of macro table
149 */
150struct macel {
151	char	 mac_name[9];	/* macro name */
152	char	*mac_start;	/* start of macro in macbuf */
153	char	*mac_end;	/* end of macro in macbuf */
154};
155
156/*
157 * Format of option table
158 */
159struct option {
160	char	*name;
161	char	*value;
162};
163
164/*
165 * Indices to features[]; an array containing status of remote server
166 * features; -1 not known (FEAT failed), 0 absent, 1 present.
167 */
168enum {
169	FEAT_FEAT = 0,		/* FEAT, OPTS */
170	FEAT_MDTM,		/* MDTM */
171	FEAT_MLST,		/* MLSD, MLST */
172	FEAT_REST_STREAM,	/* RESTart STREAM */
173	FEAT_SIZE,		/* SIZE */
174	FEAT_TVFS,		/* TVFS (not used) */
175	FEAT_max
176};
177
178
179/*
180 * Global defines
181 */
182#define	FTPBUFLEN	MAXPATHLEN + 200
183#define	MAX_IN_PORT_T	0xffffU
184
185#define	HASHBYTES	1024	/* default mark for `hash' command */
186#define	DEFAULTINCR	1024	/* default increment for `rate' command */
187
188#define	FTP_PORT	21	/* default if ! getservbyname("ftp/tcp") */
189#define	HTTP_PORT	80	/* default if ! getservbyname("http/tcp") */
190#ifndef	GATE_PORT
191#define	GATE_PORT	21	/* default if ! getservbyname("ftpgate/tcp") */
192#endif
193#ifndef	GATE_SERVER
194#define	GATE_SERVER	""	/* default server */
195#endif
196
197#define	DEFAULTPAGER	"more"	/* default pager if $PAGER isn't set */
198#define	DEFAULTPROMPT	"ftp> "	/* default prompt  if `set prompt' is empty */
199#define	DEFAULTRPROMPT	""	/* default rprompt if `set rprompt' is empty */
200
201#define	TMPFILE		"ftpXXXXXXXXXX"
202
203
204#ifndef	GLOBAL
205#define	GLOBAL	extern
206#endif
207
208/*
209 * Options and other state info.
210 */
211GLOBAL	int	trace;		/* trace packets exchanged */
212GLOBAL	int	hash;		/* print # for each buffer transferred */
213GLOBAL	int	mark;		/* number of bytes between hashes */
214GLOBAL	int	sendport;	/* use PORT/LPRT cmd for each data connection */
215GLOBAL	int	connected;	/* 1 = connected to server, -1 = logged in */
216GLOBAL	int	interactive;	/* interactively prompt on m* cmds */
217GLOBAL	int	confirmrest;	/* confirm rest of current m* cmd */
218GLOBAL	int	ftp_debug;	/* debugging level */
219GLOBAL	int	bell;		/* ring bell on cmd completion */
220GLOBAL	int	doglob;		/* glob local file names */
221GLOBAL	int	autologin;	/* establish user account on connection */
222GLOBAL	int	proxy;		/* proxy server connection active */
223GLOBAL	int	proxflag;	/* proxy connection exists */
224GLOBAL	int	gatemode;	/* use gate-ftp */
225GLOBAL	char   *gateserver;	/* server to use for gate-ftp */
226GLOBAL	int	sunique;	/* store files on server with unique name */
227GLOBAL	int	runique;	/* store local files with unique name */
228GLOBAL	int	mcase;		/* map upper to lower case for mget names */
229GLOBAL	int	ntflag;		/* use ntin ntout tables for name translation */
230GLOBAL	int	mapflag;	/* use mapin mapout templates on file names */
231GLOBAL	int	preserve;	/* preserve modification time on files */
232GLOBAL	int	code;		/* return/reply code for ftp command */
233GLOBAL	int	crflag;		/* if 1, strip car. rets. on ascii gets */
234GLOBAL	int	passivemode;	/* passive mode enabled */
235GLOBAL	int	activefallback;	/* fall back to active mode if passive fails */
236GLOBAL	char   *altarg;		/* argv[1] with no shell-like preprocessing  */
237GLOBAL	char	ntin[17];	/* input translation table */
238GLOBAL	char	ntout[17];	/* output translation table */
239GLOBAL	char	mapin[MAXPATHLEN]; /* input map template */
240GLOBAL	char	mapout[MAXPATHLEN]; /* output map template */
241GLOBAL	char	typename[32];	/* name of file transfer type */
242GLOBAL	int	type;		/* requested file transfer type */
243GLOBAL	int	curtype;	/* current file transfer type */
244GLOBAL	char	structname[32];	/* name of file transfer structure */
245GLOBAL	int	stru;		/* file transfer structure */
246GLOBAL	char	formname[32];	/* name of file transfer format */
247GLOBAL	int	form;		/* file transfer format */
248GLOBAL	char	modename[32];	/* name of file transfer mode */
249GLOBAL	int	mode;		/* file transfer mode */
250GLOBAL	char	bytename[32];	/* local byte size in ascii */
251GLOBAL	int	bytesize;	/* local byte size in binary */
252GLOBAL	int	anonftp;	/* automatic anonymous login */
253GLOBAL	int	dirchange;	/* remote directory changed by cd command */
254GLOBAL	int	flushcache;	/* set HTTP cache flush headers with request */
255GLOBAL	int	rate_get;	/* maximum get xfer rate */
256GLOBAL	int	rate_get_incr;	/* increment for get xfer rate */
257GLOBAL	int	rate_put;	/* maximum put xfer rate */
258GLOBAL	int	rate_put_incr;	/* increment for put xfer rate */
259GLOBAL	int	retry_connect;	/* seconds between retrying connection */
260GLOBAL	char   *tmpdir;		/* temporary directory */
261GLOBAL	int	epsv4;		/* use EPSV/EPRT on IPv4 connections */
262GLOBAL	int	epsv4bad;	/* EPSV doesn't work on the current server */
263GLOBAL	int	editing;	/* command line editing enabled */
264GLOBAL	int	features[FEAT_max];	/* remote FEATures supported */
265
266#ifndef NO_EDITCOMPLETE
267GLOBAL	EditLine *el;		/* editline(3) status structure */
268GLOBAL	History  *hist;		/* editline(3) history structure */
269GLOBAL	char	 *cursor_pos;	/* cursor position we're looking for */
270GLOBAL	size_t	  cursor_argc;	/* location of cursor in margv */
271GLOBAL	size_t	  cursor_argo;	/* offset of cursor in margv[cursor_argc] */
272#endif /* !NO_EDITCOMPLETE */
273
274GLOBAL	char   *direction;	/* direction transfer is occurring */
275
276GLOBAL	char   *hostname;	/* name of host connected to */
277GLOBAL	int	unix_server;	/* server is unix, can use binary for ascii */
278GLOBAL	int	unix_proxy;	/* proxy is unix, can use binary for ascii */
279GLOBAL	char	localcwd[MAXPATHLEN];	/* local dir */
280GLOBAL	char	remotecwd[MAXPATHLEN];	/* remote dir */
281GLOBAL	char   *username;	/* name of user logged in as. (dynamic) */
282
283GLOBAL	sa_family_t family;	/* address family to use for connections */
284GLOBAL	char	*ftpport;	/* port number to use for FTP connections */
285GLOBAL	char	*httpport;	/* port number to use for HTTP connections */
286GLOBAL	char	*gateport;	/* port number to use for gateftp connections */
287GLOBAL	struct addrinfo *bindai; /* local address to bind as */
288
289GLOBAL	char   *outfile;	/* filename to output URLs to */
290GLOBAL	int	restartautofetch; /* restart auto-fetch */
291
292GLOBAL	char	line[FTPBUFLEN]; /* input line buffer */
293GLOBAL	char	*stringbase;	/* current scan point in line buffer */
294GLOBAL	char	argbuf[FTPBUFLEN]; /* argument storage buffer */
295GLOBAL	char	*argbase;	/* current storage point in arg buffer */
296GLOBAL	StringList *marg_sl;	/* stringlist containing margv */
297GLOBAL	int	margc;		/* count of arguments on input line */
298#define	margv (marg_sl->sl_str)	/* args parsed from input line */
299GLOBAL	int     cpend;		/* flag: if != 0, then pending server reply */
300GLOBAL	int	mflag;		/* flag: if != 0, then active multi command */
301
302GLOBAL	int	options;	/* used during socket creation */
303
304GLOBAL	int	sndbuf_size;	/* socket send buffer size */
305GLOBAL	int	rcvbuf_size;	/* socket receive buffer size */
306
307GLOBAL	int	macnum;		/* number of defined macros */
308GLOBAL	struct macel macros[16];
309GLOBAL	char	macbuf[4096];
310
311GLOBAL	char	*localhome;		/* local home directory */
312GLOBAL	char	*localname;		/* local user name */
313GLOBAL	char	 netrc[MAXPATHLEN];	/* path to .netrc file */
314GLOBAL	char	 reply_string[BUFSIZ];	/* first line of previous reply */
315GLOBAL	void	(*reply_callback)(const char *);
316					/*
317					 * function to call for each line in
318					 * the server's reply except for the
319					 * first (`xxx-') and last (`xxx ')
320					 */
321
322GLOBAL	volatile sig_atomic_t	sigint_raised;
323
324GLOBAL	FILE	*cin;
325GLOBAL	FILE	*cout;
326GLOBAL	int	 data;
327
328extern	struct cmd	cmdtab[];
329extern	struct option	optiontab[];
330
331
332#define	EMPTYSTRING(x)	((x) == NULL || (*(x) == '\0'))
333#define	FREEPTR(x)	if ((x) != NULL) { free(x); (x) = NULL; }
334
335#ifdef BSD4_4
336# define HAVE_STRUCT_SOCKADDR_SA_LEN	1
337#endif
338
339#ifdef NO_LONG_LONG
340# define STRTOLL(x,y,z)	strtol(x,y,z)
341#else
342# define STRTOLL(x,y,z)	strtoll(x,y,z)
343#endif
344
345#ifdef NO_DEBUG
346#define DPRINTF(...)
347#define DWARN(...)
348#else
349#define DPRINTF(...)	if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__)
350#define DWARN(...) if (ftp_debug) warn(__VA_ARGS__)
351#endif
352
353#ifdef NO_USAGE
354void xusage(void);
355#define UPRINTF(...)	xusage()
356#else
357#define UPRINTF(...)	(void)fprintf(ttyout, __VA_ARGS__)
358#endif
359