1223328Sgavin/*	$NetBSD: ftp_var.h,v 1.10 2009/05/20 12:53:47 lukem Exp $	*/
2223328Sgavin/*	from	NetBSD: ftp_var.h,v 1.81 2009/04/12 10:18:52 lukem Exp	*/
379971Sobrien
479971Sobrien/*-
5223328Sgavin * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
679971Sobrien * All rights reserved.
779971Sobrien *
879971Sobrien * This code is derived from software contributed to The NetBSD Foundation
979971Sobrien * by Luke Mewburn.
1079971Sobrien *
1179971Sobrien * Redistribution and use in source and binary forms, with or without
1279971Sobrien * modification, are permitted provided that the following conditions
1379971Sobrien * are met:
1479971Sobrien * 1. Redistributions of source code must retain the above copyright
1579971Sobrien *    notice, this list of conditions and the following disclaimer.
1679971Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1779971Sobrien *    notice, this list of conditions and the following disclaimer in the
1879971Sobrien *    documentation and/or other materials provided with the distribution.
1979971Sobrien *
2079971Sobrien * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2179971Sobrien * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2279971Sobrien * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2379971Sobrien * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2479971Sobrien * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2579971Sobrien * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2679971Sobrien * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2779971Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2879971Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2979971Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3079971Sobrien * POSSIBILITY OF SUCH DAMAGE.
3179971Sobrien */
3279971Sobrien
3379971Sobrien/*
3479971Sobrien * Copyright (c) 1985, 1989, 1993, 1994
3579971Sobrien *	The Regents of the University of California.  All rights reserved.
3679971Sobrien *
3779971Sobrien * Redistribution and use in source and binary forms, with or without
3879971Sobrien * modification, are permitted provided that the following conditions
3979971Sobrien * are met:
4079971Sobrien * 1. Redistributions of source code must retain the above copyright
4179971Sobrien *    notice, this list of conditions and the following disclaimer.
4279971Sobrien * 2. Redistributions in binary form must reproduce the above copyright
4379971Sobrien *    notice, this list of conditions and the following disclaimer in the
4479971Sobrien *    documentation and/or other materials provided with the distribution.
45121966Smikeh * 3. Neither the name of the University nor the names of its contributors
4679971Sobrien *    may be used to endorse or promote products derived from this software
4779971Sobrien *    without specific prior written permission.
4879971Sobrien *
4979971Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5079971Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5179971Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5279971Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5379971Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5479971Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5579971Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5679971Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5779971Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5879971Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5979971Sobrien * SUCH DAMAGE.
6079971Sobrien *
6179971Sobrien *	@(#)ftp_var.h	8.4 (Berkeley) 10/9/94
6279971Sobrien */
6379971Sobrien
6479971Sobrien/*
6579971Sobrien * Copyright (C) 1997 and 1998 WIDE Project.
6679971Sobrien * All rights reserved.
67146309Smikeh *
6879971Sobrien * Redistribution and use in source and binary forms, with or without
6979971Sobrien * modification, are permitted provided that the following conditions
7079971Sobrien * are met:
7179971Sobrien * 1. Redistributions of source code must retain the above copyright
7279971Sobrien *    notice, this list of conditions and the following disclaimer.
7379971Sobrien * 2. Redistributions in binary form must reproduce the above copyright
7479971Sobrien *    notice, this list of conditions and the following disclaimer in the
7579971Sobrien *    documentation and/or other materials provided with the distribution.
7679971Sobrien * 3. Neither the name of the project nor the names of its contributors
7779971Sobrien *    may be used to endorse or promote products derived from this software
7879971Sobrien *    without specific prior written permission.
79146309Smikeh *
8079971Sobrien * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
8179971Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8279971Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8379971Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
8479971Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
8579971Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8679971Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8779971Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
8879971Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
8979971Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9079971Sobrien * SUCH DAMAGE.
9179971Sobrien */
9279971Sobrien
9379971Sobrien/*
9479971Sobrien * FTP global variables.
9579971Sobrien */
9679971Sobrien
9779971Sobrien#ifdef SMALL
9879971Sobrien#undef	NO_EDITCOMPLETE
9979971Sobrien#define	NO_EDITCOMPLETE
10079971Sobrien#undef	NO_PROGRESS
10179971Sobrien#define	NO_PROGRESS
10279971Sobrien#endif
10379971Sobrien
104223328Sgavin#if 0	/* tnftp */
105223328Sgavin
106116424Smikeh#include <sys/param.h>
107116424Smikeh
108116424Smikeh#include <netinet/in.h>
109116424Smikeh#include <arpa/inet.h>
110116424Smikeh
111146309Smikeh#include <poll.h>
112146309Smikeh
113116424Smikeh#include <setjmp.h>
114116424Smikeh#include <stringlist.h>
115116424Smikeh
116223328Sgavin#endif	/* tnftp */
117223328Sgavin
11879971Sobrien#ifndef NO_EDITCOMPLETE
11979971Sobrien#include <histedit.h>
12079971Sobrien#endif /* !NO_EDITCOMPLETE */
12179971Sobrien
12279971Sobrien#include "extern.h"
123116424Smikeh#include "progressbar.h"
12479971Sobrien
12579971Sobrien/*
12679971Sobrien * Format of command table.
12779971Sobrien */
12879971Sobrienstruct cmd {
129223328Sgavin	const char	*c_name;	/* name of command */
130142129Smikeh	const char	*c_help;	/* help string */
131146309Smikeh	char		c_bell;		/* give bell when command completes */
132146309Smikeh	char		c_conn;		/* must be connected to use command */
133146309Smikeh	char		c_proxy;	/* proxy server may execute */
13479971Sobrien#ifndef NO_EDITCOMPLETE
135142129Smikeh	const char	*c_complete;	/* context sensitive completion list */
13679971Sobrien#endif /* !NO_EDITCOMPLETE */
137142129Smikeh	void		(*c_handler)(int, char **); /* function to call */
13879971Sobrien};
13979971Sobrien
140223328Sgavin#define MAX_C_NAME	12		/* maximum length of cmd.c_name */
141223328Sgavin
14279971Sobrien/*
14379971Sobrien * Format of macro table
14479971Sobrien */
14579971Sobrienstruct macel {
14679971Sobrien	char	 mac_name[9];	/* macro name */
14779971Sobrien	char	*mac_start;	/* start of macro in macbuf */
14879971Sobrien	char	*mac_end;	/* end of macro in macbuf */
14979971Sobrien};
15079971Sobrien
15179971Sobrien/*
15279971Sobrien * Format of option table
15379971Sobrien */
15479971Sobrienstruct option {
155223328Sgavin	const char	*name;
156223328Sgavin	char		*value;
15779971Sobrien};
15879971Sobrien
15979971Sobrien/*
16079971Sobrien * Indices to features[]; an array containing status of remote server
16179971Sobrien * features; -1 not known (FEAT failed), 0 absent, 1 present.
16279971Sobrien */
16379971Sobrienenum {
16479971Sobrien	FEAT_FEAT = 0,		/* FEAT, OPTS */
16579971Sobrien	FEAT_MDTM,		/* MDTM */
16679971Sobrien	FEAT_MLST,		/* MLSD, MLST */
16779971Sobrien	FEAT_REST_STREAM,	/* RESTart STREAM */
16879971Sobrien	FEAT_SIZE,		/* SIZE */
16979971Sobrien	FEAT_TVFS,		/* TVFS (not used) */
17079971Sobrien	FEAT_max
17179971Sobrien};
17279971Sobrien
17379971Sobrien
17479971Sobrien/*
17579971Sobrien * Global defines
17679971Sobrien */
17779971Sobrien#define	FTPBUFLEN	MAXPATHLEN + 200
17879971Sobrien#define	MAX_IN_PORT_T	0xffffU
17979971Sobrien
18079971Sobrien#define	HASHBYTES	1024	/* default mark for `hash' command */
18179971Sobrien#define	DEFAULTINCR	1024	/* default increment for `rate' command */
18279971Sobrien
18379971Sobrien#define	FTP_PORT	21	/* default if ! getservbyname("ftp/tcp") */
18479971Sobrien#define	HTTP_PORT	80	/* default if ! getservbyname("http/tcp") */
18579971Sobrien#ifndef	GATE_PORT
18679971Sobrien#define	GATE_PORT	21	/* default if ! getservbyname("ftpgate/tcp") */
18779971Sobrien#endif
18879971Sobrien#ifndef	GATE_SERVER
18979971Sobrien#define	GATE_SERVER	""	/* default server */
19079971Sobrien#endif
19179971Sobrien
19279971Sobrien#define	DEFAULTPAGER	"more"	/* default pager if $PAGER isn't set */
19379971Sobrien#define	DEFAULTPROMPT	"ftp> "	/* default prompt  if `set prompt' is empty */
19479971Sobrien#define	DEFAULTRPROMPT	""	/* default rprompt if `set rprompt' is empty */
19579971Sobrien
19679971Sobrien#define	TMPFILE		"ftpXXXXXXXXXX"
19779971Sobrien
19879971Sobrien
19979971Sobrien#ifndef	GLOBAL
20079971Sobrien#define	GLOBAL	extern
20179971Sobrien#endif
20279971Sobrien
20379971Sobrien/*
20479971Sobrien * Options and other state info.
20579971Sobrien */
20679971SobrienGLOBAL	int	trace;		/* trace packets exchanged */
20779971SobrienGLOBAL	int	hash;		/* print # for each buffer transferred */
20879971SobrienGLOBAL	int	mark;		/* number of bytes between hashes */
20979971SobrienGLOBAL	int	sendport;	/* use PORT/LPRT cmd for each data connection */
21079971SobrienGLOBAL	int	connected;	/* 1 = connected to server, -1 = logged in */
21179971SobrienGLOBAL	int	interactive;	/* interactively prompt on m* cmds */
21279971SobrienGLOBAL	int	confirmrest;	/* confirm rest of current m* cmd */
213223328SgavinGLOBAL	int	ftp_debug;	/* debugging level */
21479971SobrienGLOBAL	int	bell;		/* ring bell on cmd completion */
21579971SobrienGLOBAL	int	doglob;		/* glob local file names */
21679971SobrienGLOBAL	int	autologin;	/* establish user account on connection */
21779971SobrienGLOBAL	int	proxy;		/* proxy server connection active */
21879971SobrienGLOBAL	int	proxflag;	/* proxy connection exists */
21979971SobrienGLOBAL	int	gatemode;	/* use gate-ftp */
220223328SgavinGLOBAL	const char *gateserver;	/* server to use for gate-ftp */
22179971SobrienGLOBAL	int	sunique;	/* store files on server with unique name */
22279971SobrienGLOBAL	int	runique;	/* store local files with unique name */
22379971SobrienGLOBAL	int	mcase;		/* map upper to lower case for mget names */
22479971SobrienGLOBAL	int	ntflag;		/* use ntin ntout tables for name translation */
22579971SobrienGLOBAL	int	mapflag;	/* use mapin mapout templates on file names */
22679971SobrienGLOBAL	int	preserve;	/* preserve modification time on files */
22779971SobrienGLOBAL	int	code;		/* return/reply code for ftp command */
22879971SobrienGLOBAL	int	crflag;		/* if 1, strip car. rets. on ascii gets */
22979971SobrienGLOBAL	int	passivemode;	/* passive mode enabled */
23079971SobrienGLOBAL	int	activefallback;	/* fall back to active mode if passive fails */
23179971SobrienGLOBAL	char   *altarg;		/* argv[1] with no shell-like preprocessing  */
23279971SobrienGLOBAL	char	ntin[17];	/* input translation table */
23379971SobrienGLOBAL	char	ntout[17];	/* output translation table */
23479971SobrienGLOBAL	char	mapin[MAXPATHLEN]; /* input map template */
23579971SobrienGLOBAL	char	mapout[MAXPATHLEN]; /* output map template */
23679971SobrienGLOBAL	char	typename[32];	/* name of file transfer type */
23779971SobrienGLOBAL	int	type;		/* requested file transfer type */
23879971SobrienGLOBAL	int	curtype;	/* current file transfer type */
23979971SobrienGLOBAL	char	structname[32];	/* name of file transfer structure */
24079971SobrienGLOBAL	int	stru;		/* file transfer structure */
24179971SobrienGLOBAL	char	formname[32];	/* name of file transfer format */
24279971SobrienGLOBAL	int	form;		/* file transfer format */
24379971SobrienGLOBAL	char	modename[32];	/* name of file transfer mode */
24479971SobrienGLOBAL	int	mode;		/* file transfer mode */
24579971SobrienGLOBAL	char	bytename[32];	/* local byte size in ascii */
24679971SobrienGLOBAL	int	bytesize;	/* local byte size in binary */
24779971SobrienGLOBAL	int	anonftp;	/* automatic anonymous login */
24879971SobrienGLOBAL	int	dirchange;	/* remote directory changed by cd command */
24979971SobrienGLOBAL	int	flushcache;	/* set HTTP cache flush headers with request */
25079971SobrienGLOBAL	int	rate_get;	/* maximum get xfer rate */
25179971SobrienGLOBAL	int	rate_get_incr;	/* increment for get xfer rate */
25279971SobrienGLOBAL	int	rate_put;	/* maximum put xfer rate */
25379971SobrienGLOBAL	int	rate_put_incr;	/* increment for put xfer rate */
25479971SobrienGLOBAL	int	retry_connect;	/* seconds between retrying connection */
255223328SgavinGLOBAL	const char *tmpdir;	/* temporary directory */
25679971SobrienGLOBAL	int	epsv4;		/* use EPSV/EPRT on IPv4 connections */
25779971SobrienGLOBAL	int	epsv4bad;	/* EPSV doesn't work on the current server */
258223328SgavinGLOBAL	int	epsv6;		/* use EPSV/EPRT on IPv6 connections */
259223328SgavinGLOBAL	int	epsv6bad;	/* EPSV doesn't work on the current server */
26079971SobrienGLOBAL	int	editing;	/* command line editing enabled */
26179971SobrienGLOBAL	int	features[FEAT_max];	/* remote FEATures supported */
26279971Sobrien
26379971Sobrien#ifndef NO_EDITCOMPLETE
26479971SobrienGLOBAL	EditLine *el;		/* editline(3) status structure */
26579971SobrienGLOBAL	History  *hist;		/* editline(3) history structure */
26679971SobrienGLOBAL	char	 *cursor_pos;	/* cursor position we're looking for */
26779971SobrienGLOBAL	size_t	  cursor_argc;	/* location of cursor in margv */
26879971SobrienGLOBAL	size_t	  cursor_argo;	/* offset of cursor in margv[cursor_argc] */
26979971Sobrien#endif /* !NO_EDITCOMPLETE */
27079971Sobrien
27179971SobrienGLOBAL	char   *hostname;	/* name of host connected to */
27279971SobrienGLOBAL	int	unix_server;	/* server is unix, can use binary for ascii */
27379971SobrienGLOBAL	int	unix_proxy;	/* proxy is unix, can use binary for ascii */
274142129SmikehGLOBAL	char	localcwd[MAXPATHLEN];	/* local dir */
275142129SmikehGLOBAL	char	remotecwd[MAXPATHLEN];	/* remote dir */
27679971SobrienGLOBAL	char   *username;	/* name of user logged in as. (dynamic) */
27779971Sobrien
27895504SmikehGLOBAL	sa_family_t family;	/* address family to use for connections */
279223328SgavinGLOBAL	const char *ftpport;	/* port number to use for FTP connections */
280223328SgavinGLOBAL	const char *httpport;	/* port number to use for HTTP connections */
281223328SgavinGLOBAL	const char *gateport;	/* port number to use for gateftp connections */
282223328SgavinGLOBAL	struct addrinfo *bindai; /* local address to bind as */
28379971Sobrien
28479971SobrienGLOBAL	char   *outfile;	/* filename to output URLs to */
28579971SobrienGLOBAL	int	restartautofetch; /* restart auto-fetch */
28679971Sobrien
28779971SobrienGLOBAL	char	line[FTPBUFLEN]; /* input line buffer */
28879971SobrienGLOBAL	char	*stringbase;	/* current scan point in line buffer */
28979971SobrienGLOBAL	char	argbuf[FTPBUFLEN]; /* argument storage buffer */
29079971SobrienGLOBAL	char	*argbase;	/* current storage point in arg buffer */
29179971SobrienGLOBAL	StringList *marg_sl;	/* stringlist containing margv */
29279971SobrienGLOBAL	int	margc;		/* count of arguments on input line */
29379971Sobrien#define	margv (marg_sl->sl_str)	/* args parsed from input line */
29479971SobrienGLOBAL	int     cpend;		/* flag: if != 0, then pending server reply */
29579971SobrienGLOBAL	int	mflag;		/* flag: if != 0, then active multi command */
29679971Sobrien
29779971SobrienGLOBAL	int	options;	/* used during socket creation */
29879971Sobrien
29979971SobrienGLOBAL	int	sndbuf_size;	/* socket send buffer size */
30079971SobrienGLOBAL	int	rcvbuf_size;	/* socket receive buffer size */
30179971Sobrien
30279971SobrienGLOBAL	int	macnum;		/* number of defined macros */
30379971SobrienGLOBAL	struct macel macros[16];
30479971SobrienGLOBAL	char	macbuf[4096];
30579971Sobrien
30698247SmikehGLOBAL	char	*localhome;		/* local home directory */
30798247SmikehGLOBAL	char	*localname;		/* local user name */
30898247SmikehGLOBAL	char	 netrc[MAXPATHLEN];	/* path to .netrc file */
30979971SobrienGLOBAL	char	 reply_string[BUFSIZ];	/* first line of previous reply */
31079971SobrienGLOBAL	void	(*reply_callback)(const char *);
31179971Sobrien					/*
31279971Sobrien					 * function to call for each line in
31379971Sobrien					 * the server's reply except for the
31479971Sobrien					 * first (`xxx-') and last (`xxx ')
31579971Sobrien					 */
31679971Sobrien
317142129SmikehGLOBAL	volatile sig_atomic_t	sigint_raised;
31879971Sobrien
31979971SobrienGLOBAL	FILE	*cin;
32079971SobrienGLOBAL	FILE	*cout;
32179971SobrienGLOBAL	int	 data;
32279971Sobrien
32379971Sobrienextern	struct cmd	cmdtab[];
32479971Sobrienextern	struct option	optiontab[];
32579971Sobrien
32679971Sobrien
32779971Sobrien#define	EMPTYSTRING(x)	((x) == NULL || (*(x) == '\0'))
32879971Sobrien#define	FREEPTR(x)	if ((x) != NULL) { free(x); (x) = NULL; }
32979971Sobrien
33079971Sobrien#ifdef BSD4_4
331223328Sgavin# define HAVE_STRUCT_SOCKADDR_IN_SIN_LEN	1
33279971Sobrien#endif
33379971Sobrien
33479971Sobrien#ifdef NO_LONG_LONG
33579971Sobrien# define STRTOLL(x,y,z)	strtol(x,y,z)
33679971Sobrien#else
33798247Smikeh# define STRTOLL(x,y,z)	strtoll(x,y,z)
33879971Sobrien#endif
339223328Sgavin
340223328Sgavin#ifdef NO_DEBUG
341223328Sgavin#define DPRINTF(...)
342223328Sgavin#define DWARN(...)
343223328Sgavin#else
344223328Sgavin#define DPRINTF(...)	if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__)
345223328Sgavin#define DWARN(...)	if (ftp_debug) warn(__VA_ARGS__)
346223328Sgavin#endif
347223328Sgavin
348223328Sgavin#define STRorNULL(s)	((s) ? (s) : "<null>")
349223328Sgavin
350223328Sgavin#ifdef NO_USAGE
351223328Sgavinvoid xusage(void);
352223328Sgavin#define UPRINTF(...)	xusage()
353223328Sgavin#else
354223328Sgavin#define UPRINTF(...)	(void)fprintf(ttyout, __VA_ARGS__)
355223328Sgavin#endif
356