Merge branch 'vendor/MDOCML'
[dragonfly.git] / contrib / tnftp / ftp_var.h
CommitLineData
a83a5d06 1/* $NetBSD: ftp_var.h,v 1.82 2012/12/21 18:07:36 christos Exp $ */
eedc536d
PA
2
3/*-
20e59a13 4 * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
eedc536d
PA
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.
eedc536d
PA
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>
3aa3fd83 104#include <sys/socket.h>
eedc536d
PA
105
106#include <netinet/in.h>
107#include <arpa/inet.h>
108
109#include <poll.h>
110
111#include <setjmp.h>
112#include <stringlist.h>
113
114#ifndef NO_EDITCOMPLETE
115#include <histedit.h>
116#endif /* !NO_EDITCOMPLETE */
117
118#include "extern.h"
119#include "progressbar.h"
120
121/*
122 * Format of command table.
123 */
124struct cmd {
20e59a13 125 const char *c_name; /* name of command */
eedc536d
PA
126 const char *c_help; /* help string */
127 char c_bell; /* give bell when command completes */
128 char c_conn; /* must be connected to use command */
129 char c_proxy; /* proxy server may execute */
130#ifndef NO_EDITCOMPLETE
131 const char *c_complete; /* context sensitive completion list */
132#endif /* !NO_EDITCOMPLETE */
133 void (*c_handler)(int, char **); /* function to call */
134};
135
20e59a13
PA
136#define MAX_C_NAME 12 /* maximum length of cmd.c_name */
137
eedc536d
PA
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 {
20e59a13
PA
151 const char *name;
152 char *value;
eedc536d
PA
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
179#define FTP_PORT 21 /* default if ! getservbyname("ftp/tcp") */
180#define HTTP_PORT 80 /* default if ! getservbyname("http/tcp") */
a83a5d06 181#define HTTPS_PORT 443 /* default if ! getservbyname("https/tcp") */
eedc536d
PA
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 connected; /* 1 = connected to server, -1 = logged in */
208GLOBAL int interactive; /* interactively prompt on m* cmds */
209GLOBAL int confirmrest; /* confirm rest of current m* cmd */
0511850f 210GLOBAL int ftp_debug; /* debugging level */
eedc536d
PA
211GLOBAL int bell; /* ring bell on cmd completion */
212GLOBAL int doglob; /* glob local file names */
213GLOBAL int autologin; /* establish user account on connection */
214GLOBAL int proxy; /* proxy server connection active */
215GLOBAL int proxflag; /* proxy connection exists */
216GLOBAL int gatemode; /* use gate-ftp */
20e59a13 217GLOBAL const char *gateserver; /* server to use for gate-ftp */
eedc536d
PA
218GLOBAL int sunique; /* store files on server with unique name */
219GLOBAL int runique; /* store local files with unique name */
220GLOBAL int mcase; /* map upper to lower case for mget names */
221GLOBAL int ntflag; /* use ntin ntout tables for name translation */
222GLOBAL int mapflag; /* use mapin mapout templates on file names */
223GLOBAL int preserve; /* preserve modification time on files */
224GLOBAL int code; /* return/reply code for ftp command */
225GLOBAL int crflag; /* if 1, strip car. rets. on ascii gets */
226GLOBAL int passivemode; /* passive mode enabled */
227GLOBAL int activefallback; /* fall back to active mode if passive fails */
228GLOBAL char *altarg; /* argv[1] with no shell-like preprocessing */
229GLOBAL char ntin[17]; /* input translation table */
230GLOBAL char ntout[17]; /* output translation table */
231GLOBAL char mapin[MAXPATHLEN]; /* input map template */
232GLOBAL char mapout[MAXPATHLEN]; /* output map template */
233GLOBAL char typename[32]; /* name of file transfer type */
234GLOBAL int type; /* requested file transfer type */
235GLOBAL int curtype; /* current file transfer type */
236GLOBAL char structname[32]; /* name of file transfer structure */
237GLOBAL int stru; /* file transfer structure */
238GLOBAL char formname[32]; /* name of file transfer format */
239GLOBAL int form; /* file transfer format */
240GLOBAL char modename[32]; /* name of file transfer mode */
241GLOBAL int mode; /* file transfer mode */
242GLOBAL char bytename[32]; /* local byte size in ascii */
243GLOBAL int bytesize; /* local byte size in binary */
244GLOBAL int anonftp; /* automatic anonymous login */
245GLOBAL int dirchange; /* remote directory changed by cd command */
246GLOBAL int flushcache; /* set HTTP cache flush headers with request */
247GLOBAL int rate_get; /* maximum get xfer rate */
248GLOBAL int rate_get_incr; /* increment for get xfer rate */
249GLOBAL int rate_put; /* maximum put xfer rate */
250GLOBAL int rate_put_incr; /* increment for put xfer rate */
251GLOBAL int retry_connect; /* seconds between retrying connection */
20e59a13 252GLOBAL const char *tmpdir; /* temporary directory */
eedc536d
PA
253GLOBAL int epsv4; /* use EPSV/EPRT on IPv4 connections */
254GLOBAL int epsv4bad; /* EPSV doesn't work on the current server */
fa70ef36
PA
255GLOBAL int epsv6; /* use EPSV/EPRT on IPv6 connections */
256GLOBAL int epsv6bad; /* EPSV doesn't work on the current server */
eedc536d
PA
257GLOBAL int editing; /* command line editing enabled */
258GLOBAL int features[FEAT_max]; /* remote FEATures supported */
259
260#ifndef NO_EDITCOMPLETE
261GLOBAL EditLine *el; /* editline(3) status structure */
262GLOBAL History *hist; /* editline(3) history structure */
263GLOBAL char *cursor_pos; /* cursor position we're looking for */
264GLOBAL size_t cursor_argc; /* location of cursor in margv */
265GLOBAL size_t cursor_argo; /* offset of cursor in margv[cursor_argc] */
266#endif /* !NO_EDITCOMPLETE */
267
eedc536d
PA
268GLOBAL char *hostname; /* name of host connected to */
269GLOBAL int unix_server; /* server is unix, can use binary for ascii */
270GLOBAL int unix_proxy; /* proxy is unix, can use binary for ascii */
271GLOBAL char localcwd[MAXPATHLEN]; /* local dir */
272GLOBAL char remotecwd[MAXPATHLEN]; /* remote dir */
273GLOBAL char *username; /* name of user logged in as. (dynamic) */
274
275GLOBAL sa_family_t family; /* address family to use for connections */
20e59a13
PA
276GLOBAL const char *ftpport; /* port number to use for FTP connections */
277GLOBAL const char *httpport; /* port number to use for HTTP connections */
a83a5d06
PA
278#ifdef WITH_SSL
279GLOBAL const char *httpsport; /* port number to use for HTTPS connections */
280#endif
20e59a13 281GLOBAL const char *gateport; /* port number to use for gateftp connections */
0511850f 282GLOBAL struct addrinfo *bindai; /* local address to bind as */
eedc536d
PA
283
284GLOBAL char *outfile; /* filename to output URLs to */
285GLOBAL int restartautofetch; /* restart auto-fetch */
286
287GLOBAL char line[FTPBUFLEN]; /* input line buffer */
288GLOBAL char *stringbase; /* current scan point in line buffer */
289GLOBAL char argbuf[FTPBUFLEN]; /* argument storage buffer */
290GLOBAL char *argbase; /* current storage point in arg buffer */
291GLOBAL StringList *marg_sl; /* stringlist containing margv */
292GLOBAL int margc; /* count of arguments on input line */
293#define margv (marg_sl->sl_str) /* args parsed from input line */
294GLOBAL int cpend; /* flag: if != 0, then pending server reply */
295GLOBAL int mflag; /* flag: if != 0, then active multi command */
296
297GLOBAL int options; /* used during socket creation */
298
299GLOBAL int sndbuf_size; /* socket send buffer size */
300GLOBAL int rcvbuf_size; /* socket receive buffer size */
301
302GLOBAL int macnum; /* number of defined macros */
303GLOBAL struct macel macros[16];
304GLOBAL char macbuf[4096];
305
306GLOBAL char *localhome; /* local home directory */
307GLOBAL char *localname; /* local user name */
308GLOBAL char netrc[MAXPATHLEN]; /* path to .netrc file */
309GLOBAL char reply_string[BUFSIZ]; /* first line of previous reply */
310GLOBAL void (*reply_callback)(const char *);
311 /*
312 * function to call for each line in
313 * the server's reply except for the
314 * first (`xxx-') and last (`xxx ')
315 */
316
317GLOBAL volatile sig_atomic_t sigint_raised;
318
319GLOBAL FILE *cin;
320GLOBAL FILE *cout;
321GLOBAL int data;
322
323extern struct cmd cmdtab[];
324extern struct option optiontab[];
325
326
327#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
328#define FREEPTR(x) if ((x) != NULL) { free(x); (x) = NULL; }
329
330#ifdef BSD4_4
3b706bf0 331# define HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 1
eedc536d
PA
332#endif
333
334#ifdef NO_LONG_LONG
335# define STRTOLL(x,y,z) strtol(x,y,z)
336#else
337# define STRTOLL(x,y,z) strtoll(x,y,z)
338#endif
339
340#ifdef NO_DEBUG
341#define DPRINTF(...)
342#define DWARN(...)
343#else
344#define DPRINTF(...) if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__)
3b706bf0 345#define DWARN(...) if (ftp_debug) warn(__VA_ARGS__)
eedc536d
PA
346#endif
347
3b706bf0
PA
348#define STRorNULL(s) ((s) ? (s) : "<null>")
349
eedc536d
PA
350#ifdef NO_USAGE
351void xusage(void);
352#define UPRINTF(...) xusage()
353#else
354#define UPRINTF(...) (void)fprintf(ttyout, __VA_ARGS__)
355#endif