ftp_var.h revision 1.37 1 /* $NetBSD: ftp_var.h,v 1.37 1999/09/30 23:51:27 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1985, 1989, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)ftp_var.h 8.4 (Berkeley) 10/9/94
36 */
37
38 /*
39 * Copyright (C) 1997 and 1998 WIDE Project.
40 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the project nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 */
66
67 /*
68 * FTP global variables.
69 */
70
71 #ifdef SMALL
72 #undef NO_ABOUT
73 #define NO_ABOUT
74 #undef NO_EDITCOMPLETE
75 #define NO_EDITCOMPLETE
76 #undef NO_PROGRESS
77 #define NO_PROGRESS
78 #endif
79
80 #include <sys/param.h>
81
82 #include <netinet/in.h>
83 #include <arpa/inet.h>
84
85 #include <setjmp.h>
86 #include <stringlist.h>
87
88 #ifndef NO_EDITCOMPLETE
89 #include <histedit.h>
90 #endif /* !NO_EDITCOMPLETE */
91
92 #include "extern.h"
93
94 #define FTPBUFLEN MAXPATHLEN + 200
95 #define MAX_IN_PORT_T 0xffffU
96
97 #define HASHBYTES 1024 /* default mark for `hash' command */
98 #define DEFAULTINCR 1024 /* default increment for `rate' command */
99 #define STALLTIME 5 /* # of seconds of no xfer before "stalling" */
100
101 #define FTP_PORT 21 /* default if ! getservbyname("ftp/tcp") */
102 #define HTTP_PORT 80 /* default if ! getservbyname("http/tcp") */
103 #ifndef GATE_PORT
104 #define GATE_PORT 21 /* default if ! getservbyname("ftpgate/tcp") */
105 #endif
106 #ifndef GATE_SERVER
107 #define GATE_SERVER "" /* default server */
108 #endif
109
110 #define PAGER "more" /* default pager if $PAGER isn't set */
111
112 /*
113 * Options and other state info.
114 */
115 int trace; /* trace packets exchanged */
116 int hash; /* print # for each buffer transferred */
117 int mark; /* number of bytes between hashes */
118 int sendport; /* use PORT/LPRT cmd for each data connection */
119 int verbose; /* print messages coming back from server */
120 int connected; /* 1 = connected to server, -1 = logged in */
121 int fromatty; /* input is from a terminal */
122 int interactive; /* interactively prompt on m* cmds */
123 int confirmrest; /* confirm rest of current m* cmd */
124 int debug; /* debugging level */
125 int bell; /* ring bell on cmd completion */
126 int doglob; /* glob local file names */
127 int autologin; /* establish user account on connection */
128 int proxy; /* proxy server connection active */
129 int proxflag; /* proxy connection exists */
130 int gatemode; /* use gate-ftp */
131 char *gateserver; /* server to use for gate-ftp */
132 int sunique; /* store files on server with unique name */
133 int runique; /* store local files with unique name */
134 int mcase; /* map upper to lower case for mget names */
135 int ntflag; /* use ntin ntout tables for name translation */
136 int mapflag; /* use mapin mapout templates on file names */
137 int preserve; /* preserve modification time on files */
138 int progress; /* display transfer progress bar */
139 int code; /* return/reply code for ftp command */
140 int crflag; /* if 1, strip car. rets. on ascii gets */
141 char pasv[BUFSIZ]; /* passive port for proxy data connection */
142 int passivemode; /* passive mode enabled */
143 int activefallback; /* fall back to active mode if passive fails */
144 char *altarg; /* argv[1] with no shell-like preprocessing */
145 char ntin[17]; /* input translation table */
146 char ntout[17]; /* output translation table */
147 char mapin[MAXPATHLEN]; /* input map template */
148 char mapout[MAXPATHLEN]; /* output map template */
149 char typename[32]; /* name of file transfer type */
150 int type; /* requested file transfer type */
151 int curtype; /* current file transfer type */
152 char structname[32]; /* name of file transfer structure */
153 int stru; /* file transfer structure */
154 char formname[32]; /* name of file transfer format */
155 int form; /* file transfer format */
156 char modename[32]; /* name of file transfer mode */
157 int mode; /* file transfer mode */
158 char bytename[32]; /* local byte size in ascii */
159 int bytesize; /* local byte size in binary */
160 int anonftp; /* automatic anonymous login */
161 int dirchange; /* remote directory changed by cd command */
162 int flushcache; /* set HTTP cache flush headers with request */
163 int rate_get; /* maximum get xfer rate */
164 int rate_get_incr; /* increment for get xfer rate */
165 int rate_put; /* maximum put xfer rate */
166 int rate_put_incr; /* increment for put xfer rate */
167 int retry_connect; /* seconds between retrying connection */
168 int ttywidth; /* width of tty */
169 char *tmpdir; /* temporary directory */
170 FILE *ttyout; /* stdout, or stderr if retrieving to stdout */
171 int epsv4; /* use EPSV/EPRT on IPv4 connections */
172
173 #ifndef NO_EDITCOMPLETE
174 int editing; /* command line editing enabled */
175 EditLine *el; /* editline(3) status structure */
176 History *hist; /* editline(3) history structure */
177 char *cursor_pos; /* cursor position we're looking for */
178 size_t cursor_argc; /* location of cursor in margv */
179 size_t cursor_argo; /* offset of cursor in margv[cursor_argc] */
180 #endif /* !NO_EDITCOMPLETE */
181
182 off_t bytes; /* current # of bytes read */
183 off_t filesize; /* size of file being transferred */
184 char *direction; /* direction transfer is occurring */
185 off_t restart_point; /* offset to restart transfer */
186
187 char *hostname; /* name of host connected to */
188 int unix_server; /* server is unix, can use binary for ascii */
189 int unix_proxy; /* proxy is unix, can use binary for ascii */
190
191 char *ftpport; /* port number to use for FTP connections */
192 char *httpport; /* port number to use for HTTP connections */
193 char *gateport; /* port number to use for gateftp connections */
194
195 const char *ftpproxy; /* ftp:// proxy server */
196 const char *httpproxy; /* http:// proxy server */
197 const char *no_proxy; /* list of domains not to proxy */
198
199 char *outfile; /* filename to output URLs to */
200 int restartautofetch; /* restart auto-fetch */
201
202 jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
203
204 char line[FTPBUFLEN]; /* input line buffer */
205 char *stringbase; /* current scan point in line buffer */
206 char argbuf[FTPBUFLEN]; /* argument storage buffer */
207 char *argbase; /* current storage point in arg buffer */
208 StringList *marg_sl; /* stringlist containing margv */
209 int margc; /* count of arguments on input line */
210 #define margv (marg_sl->sl_str) /* args parsed from input line */
211 int cpend; /* flag: if != 0, then pending server reply */
212 int mflag; /* flag: if != 0, then active multi command */
213
214 int options; /* used during socket creation */
215
216 int sndbuf_size; /* socket send buffer size */
217 int rcvbuf_size; /* socket receive buffer size */
218
219 /*
220 * Format of command table.
221 */
222 struct cmd {
223 char *c_name; /* name of command */
224 char *c_help; /* help string */
225 char c_bell; /* give bell when command completes */
226 char c_conn; /* must be connected to use command */
227 char c_proxy; /* proxy server may execute */
228 #ifndef NO_EDITCOMPLETE
229 char *c_complete; /* context sensitive completion list */
230 #endif /* !NO_EDITCOMPLETE */
231 void (*c_handler) __P((int, char **)); /* function to call */
232 };
233
234 struct macel {
235 char mac_name[9]; /* macro name */
236 char *mac_start; /* start of macro in macbuf */
237 char *mac_end; /* end of macro in macbuf */
238 };
239
240 int macnum; /* number of defined macros */
241 struct macel macros[16];
242 char macbuf[4096];
243