Merge branch 'vendor/MDOCML'
[dragonfly.git] / contrib / tnftp / cmdtab.c
1 /*      $NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp $     */
2
3 /*-
4  * Copyright (c) 1996-2009 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  *
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
61 #include <sys/cdefs.h>
62 #ifndef lint
63 #if 0
64 static char sccsid[] = "@(#)cmdtab.c    8.4 (Berkeley) 10/9/94";
65 #else
66 __RCSID("$NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp $");
67 #endif
68 #endif /* not lint */
69
70 #include <stdio.h>
71 #include "ftp_var.h"
72
73 /*
74  * User FTP -- Command Tables.
75  */
76
77 #define HSTR    static const char
78
79 #ifndef NO_HELP
80 HSTR    accounthelp[] = "send account command to remote server";
81 HSTR    appendhelp[] =  "append to a file";
82 HSTR    asciihelp[] =   "set ascii transfer type";
83 HSTR    beephelp[] =    "beep when command completed";
84 HSTR    binaryhelp[] =  "set binary transfer type";
85 HSTR    casehelp[] =    "toggle mget upper/lower case id mapping";
86 HSTR    cdhelp[] =      "change remote working directory";
87 HSTR    cduphelp[] =    "change remote working directory to parent directory";
88 HSTR    chmodhelp[] =   "change file permissions of remote file";
89 HSTR    connecthelp[] = "connect to remote ftp server";
90 HSTR    crhelp[] =      "toggle carriage return stripping on ascii gets";
91 HSTR    debughelp[] =   "toggle/set debugging mode";
92 HSTR    deletehelp[] =  "delete remote file";
93 HSTR    disconhelp[] =  "terminate ftp session";
94 HSTR    domachelp[] =   "execute macro";
95 HSTR    edithelp[] =    "toggle command line editing";
96 HSTR    epsvhelp[] =    "toggle use of EPSV/EPRT on both IPv4 and IPV6 ftp";
97 HSTR    epsv4help[] =   "toggle use of EPSV/EPRT on IPv4 ftp";
98 HSTR    epsv6help[] =   "toggle use of EPSV/EPRT on IPv6 ftp";
99 HSTR    feathelp[] =    "show FEATures supported by remote system";
100 HSTR    formhelp[] =    "set file transfer format";
101 HSTR    gatehelp[] =    "toggle gate-ftp; specify host[:port] to change proxy";
102 HSTR    globhelp[] =    "toggle metacharacter expansion of local file names";
103 HSTR    hashhelp[] =    "toggle printing `#' marks; specify number to set size";
104 HSTR    helphelp[] =    "print local help information";
105 HSTR    idlehelp[] =    "get (set) idle timer on remote side";
106 HSTR    lcdhelp[] =     "change local working directory";
107 HSTR    lpagehelp[] =   "view a local file through your pager";
108 HSTR    lpwdhelp[] =    "print local working directory";
109 HSTR    lshelp[] =      "list contents of remote path";
110 HSTR    macdefhelp[] =  "define a macro";
111 HSTR    mdeletehelp[] = "delete multiple files";
112 HSTR    mgethelp[] =    "get multiple files";
113 HSTR    mregethelp[] =  "get multiple files restarting at end of local file";
114 HSTR    fgethelp[] =    "get files using a localfile as a source of names";
115 HSTR    mkdirhelp[] =   "make directory on the remote machine";
116 HSTR    mlshelp[] =     "list contents of multiple remote directories";
117 HSTR    mlsdhelp[] =    "list contents of remote directory in a machine "
118                         "parsable form";
119 HSTR    mlsthelp[] =    "list remote path in a machine parsable form";
120 HSTR    modehelp[] =    "set file transfer mode";
121 HSTR    modtimehelp[] = "show last modification time of remote file";
122 HSTR    mputhelp[] =    "send multiple files";
123 HSTR    newerhelp[] =   "get file if remote file is newer than local file ";
124 HSTR    nmaphelp[] =    "set templates for default file name mapping";
125 HSTR    ntranshelp[] =  "set translation table for default file name mapping";
126 HSTR    optshelp[] =    "show or set options for remote commands";
127 HSTR    pagehelp[] =    "view a remote file through your pager";
128 HSTR    passivehelp[] = "toggle use of passive transfer mode";
129 HSTR    plshelp[] =     "list contents of remote path through your pager";
130 HSTR    pmlsdhelp[] =   "list contents of remote directory in a machine "
131                         "parsable form through your pager";
132 HSTR    porthelp[] =    "toggle use of PORT/LPRT cmd for each data connection";
133 HSTR    preservehelp[] ="toggle preservation of modification time of "
134                         "retrieved files";
135 HSTR    progresshelp[] ="toggle transfer progress meter";
136 HSTR    prompthelp[] =  "force interactive prompting on multiple commands";
137 HSTR    proxyhelp[] =   "issue command on alternate connection";
138 HSTR    pwdhelp[] =     "print working directory on remote machine";
139 HSTR    quithelp[] =    "terminate ftp session and exit";
140 HSTR    quotehelp[] =   "send arbitrary ftp command";
141 HSTR    ratehelp[] =    "set transfer rate limit (in bytes/second)";
142 HSTR    receivehelp[] = "receive file";
143 HSTR    regethelp[] =   "get file restarting at end of local file";
144 HSTR    remotehelp[] =  "get help from remote server";
145 HSTR    renamehelp[] =  "rename file";
146 HSTR    resethelp[] =   "clear queued command replies";
147 HSTR    restarthelp[]=  "restart file transfer at bytecount";
148 HSTR    rmdirhelp[] =   "remove directory on the remote machine";
149 HSTR    rmtstatushelp[]="show status of remote machine";
150 HSTR    runiquehelp[] = "toggle store unique for local files";
151 HSTR    sendhelp[] =    "send one file";
152 HSTR    sethelp[] =     "set or display options";
153 HSTR    shellhelp[] =   "escape to the shell";
154 HSTR    sitehelp[] =    "send site specific command to remote server\n"
155                         "\t\tTry \"rhelp site\" or \"site help\" "
156                         "for more information";
157 HSTR    sizecmdhelp[] = "show size of remote file";
158 HSTR    statushelp[] =  "show current status";
159 HSTR    structhelp[] =  "set file transfer structure";
160 HSTR    suniquehelp[] = "toggle store unique on remote machine";
161 HSTR    systemhelp[] =  "show remote system type";
162 HSTR    tenexhelp[] =   "set tenex file transfer type";
163 HSTR    tracehelp[] =   "toggle packet tracing";
164 HSTR    typehelp[] =    "set file transfer type";
165 HSTR    umaskhelp[] =   "get (set) umask on remote side";
166 HSTR    unsethelp[] =   "unset an option";
167 HSTR    usagehelp[] =   "show command usage";
168 HSTR    userhelp[] =    "send new user information";
169 HSTR    verbosehelp[] = "toggle verbose mode";
170 HSTR    xferbufhelp[] = "set socket send/receive buffer size";
171 #endif
172
173 HSTR    empty[] = "";
174
175 #ifdef NO_HELP
176 #define H(x)    empty
177 #else
178 #define H(x)    x
179 #endif
180
181 #ifdef NO_EDITCOMPLETE
182 #define CMPL(x)
183 #define CMPL0
184 #else  /* !NO_EDITCOMPLETE */
185 #define CMPL(x) #x,
186 #define CMPL0   empty,
187 #endif /* !NO_EDITCOMPLETE */
188
189 struct cmd cmdtab[] = {
190         { "!",          H(shellhelp),   0, 0, 0, CMPL0          shell },
191         { "$",          H(domachelp),   1, 0, 0, CMPL0          domacro },
192         { "account",    H(accounthelp), 0, 1, 1, CMPL0          account},
193         { "append",     H(appendhelp),  1, 1, 1, CMPL(lr)       put },
194         { "ascii",      H(asciihelp),   0, 1, 1, CMPL0          setascii },
195         { "bell",       H(beephelp),    0, 0, 0, CMPL0          setbell },
196         { "binary",     H(binaryhelp),  0, 1, 1, CMPL0          setbinary },
197         { "bye",        H(quithelp),    0, 0, 0, CMPL0          quit },
198         { "case",       H(casehelp),    0, 0, 1, CMPL0          setcase },
199         { "cd",         H(cdhelp),      0, 1, 1, CMPL(r)        cd },
200         { "cdup",       H(cduphelp),    0, 1, 1, CMPL0          cdup },
201         { "chmod",      H(chmodhelp),   0, 1, 1, CMPL(nr)       do_chmod },
202         { "close",      H(disconhelp),  0, 1, 1, CMPL0          disconnect },
203         { "cr",         H(crhelp),      0, 0, 0, CMPL0          setcr },
204         { "debug",      H(debughelp),   0, 0, 0, CMPL0          setdebug },
205         { "delete",     H(deletehelp),  0, 1, 1, CMPL(r)        delete },
206         { "dir",        H(lshelp),      1, 1, 1, CMPL(rl)       ls },
207         { "disconnect", H(disconhelp),  0, 1, 1, CMPL0          disconnect },
208         { "edit",       H(edithelp),    0, 0, 0, CMPL0          setedit },
209         { "epsv",       H(epsvhelp),    0, 0, 0, CMPL0          setepsv },
210         { "epsv4",      H(epsv4help),   0, 0, 0, CMPL0          setepsv4 },
211         { "epsv6",      H(epsv6help),   0, 0, 0, CMPL0          setepsv6 },
212         { "exit",       H(quithelp),    0, 0, 0, CMPL0          quit },
213         { "features",   H(feathelp),    0, 1, 1, CMPL0          feat },
214         { "fget",       H(fgethelp),    1, 1, 1, CMPL(l)        fget },
215         { "form",       H(formhelp),    0, 1, 1, CMPL0          setform },
216         { "ftp",        H(connecthelp), 0, 0, 1, CMPL0          setpeer },
217         { "gate",       H(gatehelp),    0, 0, 0, CMPL0          setgate },
218         { "get",        H(receivehelp), 1, 1, 1, CMPL(rl)       get },
219         { "glob",       H(globhelp),    0, 0, 0, CMPL0          setglob },
220         { "hash",       H(hashhelp),    0, 0, 0, CMPL0          sethash },
221         { "help",       H(helphelp),    0, 0, 1, CMPL(C)        help },
222         { "idle",       H(idlehelp),    0, 1, 1, CMPL0          idlecmd },
223         { "image",      H(binaryhelp),  0, 1, 1, CMPL0          setbinary },
224         { "lcd",        H(lcdhelp),     0, 0, 0, CMPL(l)        lcd },
225         { "less",       H(pagehelp),    1, 1, 1, CMPL(r)        page },
226         { "lpage",      H(lpagehelp),   0, 0, 0, CMPL(l)        lpage },
227         { "lpwd",       H(lpwdhelp),    0, 0, 0, CMPL0          lpwd },
228         { "ls",         H(lshelp),      1, 1, 1, CMPL(rl)       ls },
229         { "macdef",     H(macdefhelp),  0, 0, 0, CMPL0          macdef },
230         { "mdelete",    H(mdeletehelp), 1, 1, 1, CMPL(R)        mdelete },
231         { "mdir",       H(mlshelp),     1, 1, 1, CMPL(R)        mls },
232         { "mget",       H(mgethelp),    1, 1, 1, CMPL(R)        mget },
233         { "mkdir",      H(mkdirhelp),   0, 1, 1, CMPL(r)        makedir },
234         { "mls",        H(mlshelp),     1, 1, 1, CMPL(R)        mls },
235         { "mlsd",       H(mlsdhelp),    1, 1, 1, CMPL(r)        ls },
236         { "mlst",       H(mlsthelp),    1, 1, 1, CMPL(r)        mlst },
237         { "mode",       H(modehelp),    0, 1, 1, CMPL0          setftmode },
238         { "modtime",    H(modtimehelp), 0, 1, 1, CMPL(r)        modtime },
239         { "more",       H(pagehelp),    1, 1, 1, CMPL(r)        page },
240         { "mput",       H(mputhelp),    1, 1, 1, CMPL(L)        mput },
241         { "mreget",     H(mregethelp),  1, 1, 1, CMPL(R)        mget },
242         { "msend",      H(mputhelp),    1, 1, 1, CMPL(L)        mput },
243         { "newer",      H(newerhelp),   1, 1, 1, CMPL(r)        newer },
244         { "nlist",      H(lshelp),      1, 1, 1, CMPL(rl)       ls },
245         { "nmap",       H(nmaphelp),    0, 0, 1, CMPL0          setnmap },
246         { "ntrans",     H(ntranshelp),  0, 0, 1, CMPL0          setntrans },
247         { "open",       H(connecthelp), 0, 0, 1, CMPL0          setpeer },
248         { "page",       H(pagehelp),    1, 1, 1, CMPL(r)        page },
249         { "passive",    H(passivehelp), 0, 0, 0, CMPL0          setpassive },
250         { "pdir",       H(plshelp),     1, 1, 1, CMPL(r)        ls },
251         { "pls",        H(plshelp),     1, 1, 1, CMPL(r)        ls },
252         { "pmlsd",      H(pmlsdhelp),   1, 1, 1, CMPL(r)        ls },
253         { "preserve",   H(preservehelp),0, 0, 0, CMPL0          setpreserve },
254         { "progress",   H(progresshelp),0, 0, 0, CMPL0          setprogress },
255         { "prompt",     H(prompthelp),  0, 0, 0, CMPL0          setprompt },
256         { "proxy",      H(proxyhelp),   0, 0, 1, CMPL(c)        doproxy },
257         { "put",        H(sendhelp),    1, 1, 1, CMPL(lr)       put },
258         { "pwd",        H(pwdhelp),     0, 1, 1, CMPL0          pwd },
259         { "quit",       H(quithelp),    0, 0, 0, CMPL0          quit },
260         { "quote",      H(quotehelp),   1, 1, 1, CMPL0          quote },
261         { "rate",       H(ratehelp),    0, 0, 0, CMPL0          setrate },
262         { "rcvbuf",     H(xferbufhelp), 0, 0, 0, CMPL0          setxferbuf },
263         { "recv",       H(receivehelp), 1, 1, 1, CMPL(rl)       get },
264         { "reget",      H(regethelp),   1, 1, 1, CMPL(rl)       reget },
265         { "remopts",    H(optshelp),    0, 1, 1, CMPL0          opts },
266         { "rename",     H(renamehelp),  0, 1, 1, CMPL(rr)       renamefile },
267         { "reset",      H(resethelp),   0, 1, 1, CMPL0          reset },
268         { "restart",    H(restarthelp), 1, 1, 1, CMPL0          restart },
269         { "rhelp",      H(remotehelp),  0, 1, 1, CMPL0          rmthelp },
270         { "rmdir",      H(rmdirhelp),   0, 1, 1, CMPL(r)        removedir },
271         { "rstatus",    H(rmtstatushelp),0, 1, 1, CMPL(r)       rmtstatus },
272         { "runique",    H(runiquehelp), 0, 0, 1, CMPL0          setrunique },
273         { "send",       H(sendhelp),    1, 1, 1, CMPL(lr)       put },
274         { "sendport",   H(porthelp),    0, 0, 0, CMPL0          setport },
275         { "set",        H(sethelp),     0, 0, 0, CMPL(o)        setoption },
276         { "site",       H(sitehelp),    0, 1, 1, CMPL0          site },
277         { "size",       H(sizecmdhelp), 1, 1, 1, CMPL(r)        sizecmd },
278         { "sndbuf",     H(xferbufhelp), 0, 0, 0, CMPL0          setxferbuf },
279         { "status",     H(statushelp),  0, 0, 1, CMPL0          status },
280         { "struct",     H(structhelp),  0, 1, 1, CMPL0          setstruct },
281         { "sunique",    H(suniquehelp), 0, 0, 1, CMPL0          setsunique },
282         { "system",     H(systemhelp),  0, 1, 1, CMPL0          syst },
283         { "tenex",      H(tenexhelp),   0, 1, 1, CMPL0          settenex },
284         { "throttle",   H(ratehelp),    0, 0, 0, CMPL0          setrate },
285         { "trace",      H(tracehelp),   0, 0, 0, CMPL0          settrace },
286         { "type",       H(typehelp),    0, 1, 1, CMPL0          settype },
287         { "umask",      H(umaskhelp),   0, 1, 1, CMPL0          do_umask },
288         { "unset",      H(unsethelp),   0, 0, 0, CMPL(o)        unsetoption },
289         { "usage",      H(usagehelp),   0, 0, 1, CMPL(C)        help },
290         { "user",       H(userhelp),    0, 1, 1, CMPL0          user },
291         { "verbose",    H(verbosehelp), 0, 0, 0, CMPL0          setverbose },
292         { "xferbuf",    H(xferbufhelp), 0, 0, 0, CMPL0          setxferbuf },
293         { "?",          H(helphelp),    0, 0, 1, CMPL(C)        help },
294         { NULL,         NULL,           0, 0, 0, CMPL0          NULL },
295 };
296
297 struct option optiontab[] = {
298         { "anonpass",   NULL },
299         { "ftp_proxy",  NULL },
300         { "http_proxy", NULL },
301         { "https_proxy",NULL },
302         { "no_proxy",   NULL },
303         { "pager",      NULL },
304         { "prompt",     NULL },
305         { "rprompt",    NULL },
306         { NULL,         NULL },
307 };