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