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