"Fossies" - the Fresh Open Source Software Archive

Member "tnftp-20200705/src/ftp_var.h" (4 Jul 2020, 14152 Bytes) of package /linux/privat/tnftp-20200705.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ftp_var.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 20151004_vs_20200705.

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