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