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