ftp_var.h revision 1.85.6.3
11.85.6.3Smartin/*	$NetBSD: ftp_var.h,v 1.85.6.3 2022/09/12 17:06:56 martin Exp $	*/
21.42Slukem
31.42Slukem/*-
41.81Slukem * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
51.42Slukem * All rights reserved.
61.42Slukem *
71.42Slukem * This code is derived from software contributed to The NetBSD Foundation
81.42Slukem * by Luke Mewburn.
91.42Slukem *
101.42Slukem * Redistribution and use in source and binary forms, with or without
111.42Slukem * modification, are permitted provided that the following conditions
121.42Slukem * are met:
131.42Slukem * 1. Redistributions of source code must retain the above copyright
141.42Slukem *    notice, this list of conditions and the following disclaimer.
151.42Slukem * 2. Redistributions in binary form must reproduce the above copyright
161.42Slukem *    notice, this list of conditions and the following disclaimer in the
171.42Slukem *    documentation and/or other materials provided with the distribution.
181.42Slukem *
191.42Slukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.42Slukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.42Slukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.42Slukem * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.42Slukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.42Slukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.42Slukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.42Slukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.42Slukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.42Slukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.42Slukem * POSSIBILITY OF SUCH DAMAGE.
301.42Slukem */
311.34Sitojun
321.34Sitojun/*
331.37Slukem * Copyright (c) 1985, 1989, 1993, 1994
341.37Slukem *	The Regents of the University of California.  All rights reserved.
351.37Slukem *
361.34Sitojun * Redistribution and use in source and binary forms, with or without
371.34Sitojun * modification, are permitted provided that the following conditions
381.34Sitojun * are met:
391.34Sitojun * 1. Redistributions of source code must retain the above copyright
401.34Sitojun *    notice, this list of conditions and the following disclaimer.
411.34Sitojun * 2. Redistributions in binary form must reproduce the above copyright
421.34Sitojun *    notice, this list of conditions and the following disclaimer in the
431.34Sitojun *    documentation and/or other materials provided with the distribution.
441.65Sagc * 3. Neither the name of the University nor the names of its contributors
451.34Sitojun *    may be used to endorse or promote products derived from this software
461.34Sitojun *    without specific prior written permission.
471.37Slukem *
481.37Slukem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
491.34Sitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
501.34Sitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
511.37Slukem * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
521.34Sitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
531.34Sitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
541.34Sitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
551.34Sitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
561.34Sitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
571.34Sitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
581.34Sitojun * SUCH DAMAGE.
591.37Slukem *
601.37Slukem *	@(#)ftp_var.h	8.4 (Berkeley) 10/9/94
611.34Sitojun */
621.6Stls
631.1Scgd/*
641.37Slukem * Copyright (C) 1997 and 1998 WIDE Project.
651.37Slukem * All rights reserved.
661.71Slukem *
671.1Scgd * Redistribution and use in source and binary forms, with or without
681.1Scgd * modification, are permitted provided that the following conditions
691.1Scgd * are met:
701.1Scgd * 1. Redistributions of source code must retain the above copyright
711.1Scgd *    notice, this list of conditions and the following disclaimer.
721.1Scgd * 2. Redistributions in binary form must reproduce the above copyright
731.1Scgd *    notice, this list of conditions and the following disclaimer in the
741.1Scgd *    documentation and/or other materials provided with the distribution.
751.37Slukem * 3. Neither the name of the project nor the names of its contributors
761.1Scgd *    may be used to endorse or promote products derived from this software
771.1Scgd *    without specific prior written permission.
781.71Slukem *
791.37Slukem * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
801.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
811.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
821.37Slukem * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
831.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
841.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
851.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
861.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
871.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
881.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
891.1Scgd * SUCH DAMAGE.
901.1Scgd */
911.1Scgd
921.1Scgd/*
931.1Scgd * FTP global variables.
941.1Scgd */
951.1Scgd
961.32Scgd#ifdef SMALL
971.32Scgd#undef	NO_EDITCOMPLETE
981.32Scgd#define	NO_EDITCOMPLETE
991.32Scgd#undef	NO_PROGRESS
1001.32Scgd#define	NO_PROGRESS
1011.32Scgd#endif
1021.32Scgd
1031.3Scgd#include <sys/param.h>
1041.26Slukem
1051.26Slukem#include <netinet/in.h>
1061.26Slukem#include <arpa/inet.h>
1071.26Slukem
1081.70Slukem#include <poll.h>
1091.70Slukem
1101.3Scgd#include <setjmp.h>
1111.12Slukem#include <stringlist.h>
1121.12Slukem
1131.32Scgd#ifndef NO_EDITCOMPLETE
1141.12Slukem#include <histedit.h>
1151.32Scgd#endif /* !NO_EDITCOMPLETE */
1161.52Slukem
1171.3Scgd#include "extern.h"
1181.64Sjhawk#include "progressbar.h"
1191.38Slukem
1201.38Slukem/*
1211.38Slukem * Format of command table.
1221.38Slukem */
1231.38Slukemstruct cmd {
1241.81Slukem	const char	*c_name;	/* name of command */
1251.66Schristos	const char	*c_help;	/* help string */
1261.71Slukem	char		c_bell;		/* give bell when command completes */
1271.71Slukem	char		c_conn;		/* must be connected to use command */
1281.71Slukem	char		c_proxy;	/* proxy server may execute */
1291.38Slukem#ifndef NO_EDITCOMPLETE
1301.66Schristos	const char	*c_complete;	/* context sensitive completion list */
1311.38Slukem#endif /* !NO_EDITCOMPLETE */
1321.66Schristos	void		(*c_handler)(int, char **); /* function to call */
1331.38Slukem};
1341.38Slukem
1351.81Slukem#define MAX_C_NAME	12		/* maximum length of cmd.c_name */
1361.81Slukem
1371.38Slukem/*
1381.38Slukem * Format of macro table
1391.38Slukem */
1401.38Slukemstruct macel {
1411.54Slukem	char	 mac_name[9];	/* macro name */
1421.54Slukem	char	*mac_start;	/* start of macro in macbuf */
1431.54Slukem	char	*mac_end;	/* end of macro in macbuf */
1441.38Slukem};
1451.38Slukem
1461.44Slukem/*
1471.44Slukem * Format of option table
1481.44Slukem */
1491.44Slukemstruct option {
1501.81Slukem	const char	*name;
1511.81Slukem	char		*value;
1521.44Slukem};
1531.44Slukem
1541.55Slukem/*
1551.55Slukem * Indices to features[]; an array containing status of remote server
1561.55Slukem * features; -1 not known (FEAT failed), 0 absent, 1 present.
1571.55Slukem */
1581.55Slukemenum {
1591.55Slukem	FEAT_FEAT = 0,		/* FEAT, OPTS */
1601.55Slukem	FEAT_MDTM,		/* MDTM */
1611.55Slukem	FEAT_MLST,		/* MLSD, MLST */
1621.55Slukem	FEAT_REST_STREAM,	/* RESTart STREAM */
1631.55Slukem	FEAT_SIZE,		/* SIZE */
1641.55Slukem	FEAT_TVFS,		/* TVFS (not used) */
1651.56Slukem	FEAT_max
1661.55Slukem};
1671.55Slukem
1681.38Slukem
1691.38Slukem/*
1701.38Slukem * Global defines
1711.38Slukem */
1721.83Schristos#define	FTPBUFLEN	(4 * MAXPATHLEN)
1731.41Slukem#define	MAX_IN_PORT_T	0xffffU
1741.8Slukem
1751.41Slukem#define	HASHBYTES	1024	/* default mark for `hash' command */
1761.33Slukem#define	DEFAULTINCR	1024	/* default increment for `rate' command */
1771.13Slukem
1781.18Slukem#define	FTP_PORT	21	/* default if ! getservbyname("ftp/tcp") */
1791.18Slukem#define	HTTP_PORT	80	/* default if ! getservbyname("http/tcp") */
1801.82Schristos#define	HTTPS_PORT	443	/* default if ! getservbyname("https/tcp") */
1811.18Slukem#ifndef	GATE_PORT
1821.18Slukem#define	GATE_PORT	21	/* default if ! getservbyname("ftpgate/tcp") */
1831.18Slukem#endif
1841.18Slukem#ifndef	GATE_SERVER
1851.18Slukem#define	GATE_SERVER	""	/* default server */
1861.18Slukem#endif
1871.14Slukem
1881.44Slukem#define	DEFAULTPAGER	"more"	/* default pager if $PAGER isn't set */
1891.48Slukem#define	DEFAULTPROMPT	"ftp> "	/* default prompt  if `set prompt' is empty */
1901.48Slukem#define	DEFAULTRPROMPT	""	/* default rprompt if `set rprompt' is empty */
1911.8Slukem
1921.38Slukem#define	TMPFILE		"ftpXXXXXXXXXX"
1931.38Slukem
1941.38Slukem
1951.39Slukem#ifndef	GLOBAL
1961.39Slukem#define	GLOBAL	extern
1971.39Slukem#endif
1981.39Slukem
1991.1Scgd/*
2001.1Scgd * Options and other state info.
2011.1Scgd */
2021.39SlukemGLOBAL	int	trace;		/* trace packets exchanged */
2031.39SlukemGLOBAL	int	hash;		/* print # for each buffer transferred */
2041.39SlukemGLOBAL	int	mark;		/* number of bytes between hashes */
2051.39SlukemGLOBAL	int	sendport;	/* use PORT/LPRT cmd for each data connection */
2061.39SlukemGLOBAL	int	connected;	/* 1 = connected to server, -1 = logged in */
2071.39SlukemGLOBAL	int	interactive;	/* interactively prompt on m* cmds */
2081.39SlukemGLOBAL	int	confirmrest;	/* confirm rest of current m* cmd */
2091.74SlukemGLOBAL	int	ftp_debug;	/* debugging level */
2101.39SlukemGLOBAL	int	bell;		/* ring bell on cmd completion */
2111.39SlukemGLOBAL	int	doglob;		/* glob local file names */
2121.39SlukemGLOBAL	int	autologin;	/* establish user account on connection */
2131.39SlukemGLOBAL	int	proxy;		/* proxy server connection active */
2141.39SlukemGLOBAL	int	proxflag;	/* proxy connection exists */
2151.39SlukemGLOBAL	int	gatemode;	/* use gate-ftp */
2161.81SlukemGLOBAL	const char *gateserver;	/* server to use for gate-ftp */
2171.39SlukemGLOBAL	int	sunique;	/* store files on server with unique name */
2181.39SlukemGLOBAL	int	runique;	/* store local files with unique name */
2191.39SlukemGLOBAL	int	mcase;		/* map upper to lower case for mget names */
2201.39SlukemGLOBAL	int	ntflag;		/* use ntin ntout tables for name translation */
2211.39SlukemGLOBAL	int	mapflag;	/* use mapin mapout templates on file names */
2221.39SlukemGLOBAL	int	preserve;	/* preserve modification time on files */
2231.39SlukemGLOBAL	int	code;		/* return/reply code for ftp command */
2241.39SlukemGLOBAL	int	crflag;		/* if 1, strip car. rets. on ascii gets */
2251.39SlukemGLOBAL	int	passivemode;	/* passive mode enabled */
2261.39SlukemGLOBAL	int	activefallback;	/* fall back to active mode if passive fails */
2271.39SlukemGLOBAL	char   *altarg;		/* argv[1] with no shell-like preprocessing  */
2281.39SlukemGLOBAL	char	ntin[17];	/* input translation table */
2291.39SlukemGLOBAL	char	ntout[17];	/* output translation table */
2301.39SlukemGLOBAL	char	mapin[MAXPATHLEN]; /* input map template */
2311.39SlukemGLOBAL	char	mapout[MAXPATHLEN]; /* output map template */
2321.39SlukemGLOBAL	char	typename[32];	/* name of file transfer type */
2331.39SlukemGLOBAL	int	type;		/* requested file transfer type */
2341.39SlukemGLOBAL	int	curtype;	/* current file transfer type */
2351.39SlukemGLOBAL	char	structname[32];	/* name of file transfer structure */
2361.39SlukemGLOBAL	int	stru;		/* file transfer structure */
2371.39SlukemGLOBAL	char	formname[32];	/* name of file transfer format */
2381.39SlukemGLOBAL	int	form;		/* file transfer format */
2391.39SlukemGLOBAL	char	modename[32];	/* name of file transfer mode */
2401.39SlukemGLOBAL	int	mode;		/* file transfer mode */
2411.39SlukemGLOBAL	char	bytename[32];	/* local byte size in ascii */
2421.39SlukemGLOBAL	int	bytesize;	/* local byte size in binary */
2431.39SlukemGLOBAL	int	anonftp;	/* automatic anonymous login */
2441.39SlukemGLOBAL	int	dirchange;	/* remote directory changed by cd command */
2451.39SlukemGLOBAL	int	flushcache;	/* set HTTP cache flush headers with request */
2461.39SlukemGLOBAL	int	rate_get;	/* maximum get xfer rate */
2471.39SlukemGLOBAL	int	rate_get_incr;	/* increment for get xfer rate */
2481.39SlukemGLOBAL	int	rate_put;	/* maximum put xfer rate */
2491.39SlukemGLOBAL	int	rate_put_incr;	/* increment for put xfer rate */
2501.39SlukemGLOBAL	int	retry_connect;	/* seconds between retrying connection */
2511.81SlukemGLOBAL	const char *tmpdir;	/* temporary directory */
2521.39SlukemGLOBAL	int	epsv4;		/* use EPSV/EPRT on IPv4 connections */
2531.40SlukemGLOBAL	int	epsv4bad;	/* EPSV doesn't work on the current server */
2541.79SskdGLOBAL	int	epsv6;		/* use EPSV/EPRT on IPv6 connections */
2551.79SskdGLOBAL	int	epsv6bad;	/* EPSV doesn't work on the current server */
2561.41SlukemGLOBAL	int	editing;	/* command line editing enabled */
2571.55SlukemGLOBAL	int	features[FEAT_max];	/* remote FEATures supported */
2581.12Slukem
2591.32Scgd#ifndef NO_EDITCOMPLETE
2601.39SlukemGLOBAL	EditLine *el;		/* editline(3) status structure */
2611.39SlukemGLOBAL	History  *hist;		/* editline(3) history structure */
2621.39SlukemGLOBAL	char	 *cursor_pos;	/* cursor position we're looking for */
2631.39SlukemGLOBAL	size_t	  cursor_argc;	/* location of cursor in margv */
2641.39SlukemGLOBAL	size_t	  cursor_argo;	/* offset of cursor in margv[cursor_argc] */
2651.32Scgd#endif /* !NO_EDITCOMPLETE */
2661.12Slukem
2671.39SlukemGLOBAL	char   *hostname;	/* name of host connected to */
2681.39SlukemGLOBAL	int	unix_server;	/* server is unix, can use binary for ascii */
2691.39SlukemGLOBAL	int	unix_proxy;	/* proxy is unix, can use binary for ascii */
2701.69SlukemGLOBAL	char	localcwd[MAXPATHLEN];	/* local dir */
2711.69SlukemGLOBAL	char	remotecwd[MAXPATHLEN];	/* remote dir */
2721.85SkreGLOBAL	int	remcwdvalid;		/* remotecwd has been updated */
2731.47SlukemGLOBAL	char   *username;	/* name of user logged in as. (dynamic) */
2741.39Slukem
2751.61SlukemGLOBAL	sa_family_t family;	/* address family to use for connections */
2761.81SlukemGLOBAL	const char *ftpport;	/* port number to use for FTP connections */
2771.81SlukemGLOBAL	const char *httpport;	/* port number to use for HTTP connections */
2781.82Schristos#ifdef WITH_SSL
2791.82SchristosGLOBAL	const char *httpsport;	/* port number to use for HTTPS connections */
2801.82Schristos#endif
2811.81SlukemGLOBAL	const char *gateport;	/* port number to use for gateftp connections */
2821.74SlukemGLOBAL	struct addrinfo *bindai; /* local address to bind as */
2831.39Slukem
2841.39SlukemGLOBAL	char   *outfile;	/* filename to output URLs to */
2851.39SlukemGLOBAL	int	restartautofetch; /* restart auto-fetch */
2861.39Slukem
2871.39SlukemGLOBAL	char	line[FTPBUFLEN]; /* input line buffer */
2881.39SlukemGLOBAL	char	*stringbase;	/* current scan point in line buffer */
2891.39SlukemGLOBAL	char	argbuf[FTPBUFLEN]; /* argument storage buffer */
2901.39SlukemGLOBAL	char	*argbase;	/* current storage point in arg buffer */
2911.39SlukemGLOBAL	StringList *marg_sl;	/* stringlist containing margv */
2921.39SlukemGLOBAL	int	margc;		/* count of arguments on input line */
2931.41Slukem#define	margv (marg_sl->sl_str)	/* args parsed from input line */
2941.39SlukemGLOBAL	int     cpend;		/* flag: if != 0, then pending server reply */
2951.39SlukemGLOBAL	int	mflag;		/* flag: if != 0, then active multi command */
2961.39Slukem
2971.39SlukemGLOBAL	int	options;	/* used during socket creation */
2981.39Slukem
2991.39SlukemGLOBAL	int	sndbuf_size;	/* socket send buffer size */
3001.39SlukemGLOBAL	int	rcvbuf_size;	/* socket receive buffer size */
3011.39Slukem
3021.39SlukemGLOBAL	int	macnum;		/* number of defined macros */
3031.39SlukemGLOBAL	struct macel macros[16];
3041.39SlukemGLOBAL	char	macbuf[4096];
3051.39Slukem
3061.59SlukemGLOBAL	char	*localhome;		/* local home directory */
3071.59SlukemGLOBAL	char	*localname;		/* local user name */
3081.59SlukemGLOBAL	char	 netrc[MAXPATHLEN];	/* path to .netrc file */
3091.39SlukemGLOBAL	char	 reply_string[BUFSIZ];	/* first line of previous reply */
3101.55SlukemGLOBAL	void	(*reply_callback)(const char *);
3111.55Slukem					/*
3121.55Slukem					 * function to call for each line in
3131.55Slukem					 * the server's reply except for the
3141.55Slukem					 * first (`xxx-') and last (`xxx ')
3151.55Slukem					 */
3161.55Slukem
3171.67SlukemGLOBAL	volatile sig_atomic_t	sigint_raised;
3181.1Scgd
3191.47SlukemGLOBAL	FILE	*cin;
3201.47SlukemGLOBAL	FILE	*cout;
3211.39SlukemGLOBAL	int	 data;
3221.25Sthorpej
3231.44Slukemextern	struct cmd	cmdtab[];
3241.44Slukemextern	struct option	optiontab[];
3251.44Slukem
3261.44Slukem
3271.44Slukem#define	EMPTYSTRING(x)	((x) == NULL || (*(x) == '\0'))
3281.44Slukem#define	FREEPTR(x)	if ((x) != NULL) { free(x); (x) = NULL; }
3291.57Slukem
3301.58Slukem#ifdef BSD4_4
3311.76Slukem# define HAVE_STRUCT_SOCKADDR_IN_SIN_LEN	1
3321.58Slukem#endif
3331.57Slukem
3341.58Slukem#ifdef NO_LONG_LONG
3351.57Slukem# define STRTOLL(x,y,z)	strtol(x,y,z)
3361.57Slukem#else
3371.57Slukem# define STRTOLL(x,y,z)	strtoll(x,y,z)
3381.57Slukem#endif
3391.72Schristos
3401.72Schristos#ifdef NO_DEBUG
3411.84Schristos#define DPRINTF(...)	(void)0
3421.84Schristos#define DWARN(...)	(void)0
3431.72Schristos#else
3441.85.6.3Smartin#define DWFTP(a)	do a; while (0)
3451.84Schristos#define DPRINTF(...)	DWFTP(if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__))
3461.84Schristos#define DWARN(...)	DWFTP(if (ftp_debug) warn(__VA_ARGS__))
3471.72Schristos#endif
3481.72Schristos
3491.77Slukem#define STRorNULL(s)	((s) ? (s) : "<null>")
3501.77Slukem
3511.72Schristos#ifdef NO_USAGE
3521.72Schristosvoid xusage(void);
3531.72Schristos#define UPRINTF(...)	xusage()
3541.72Schristos#else
3551.72Schristos#define UPRINTF(...)	(void)fprintf(ttyout, __VA_ARGS__)
3561.72Schristos#endif
357