1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
/* parse.c
Parse a UUCP command string.
Copyright (C) 1991, 1992, 1993, 2002 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
The author of the program may be contacted at ian@airs.com.
*/
#include "uucp.h"
#if USE_RCS_ID
const char parse_rcsid[] = "$Id: parse.c,v 1.11 2002/03/05 19:10:42 ian Rel $";
#endif
#include "uudefs.h"
/* Local functions. */
static void ulunquote_cmd P((struct scmd *qcmd));
/* Parse a UUCP command string into an scmd structure. This is called
by the 'g' protocol and the UNIX command file reading routines. It
destroys the string it is passed, and the scmd string pointers are
left pointing into it. For the convenience of the Unix work file
routines, it will parse "P" into a simple 'P' command (representing
a poll file). If 'q' appears in the options, it will unquote all
the relevant strings. It returns TRUE if the string is
successfully parsed, FALSE otherwise. */
boolean
fparse_cmd (zcmd, qcmd)
char *zcmd;
struct scmd *qcmd;
{
char *z, *zend;
z = strtok (zcmd, " \t\n");
if (z == NULL)
return FALSE;
qcmd->bcmd = *z;
if (qcmd->bcmd != 'S'
&& qcmd->bcmd != 'R'
&& qcmd->bcmd != 'X'
&& qcmd->bcmd != 'E'
&& qcmd->bcmd != 'H'
&& qcmd->bcmd != 'P')
return FALSE;
qcmd->bgrade = '\0';
qcmd->pseq = NULL;
qcmd->zfrom = NULL;
qcmd->zto = NULL;
qcmd->zuser = NULL;
qcmd->zoptions = NULL;
qcmd->ztemp = NULL;
qcmd->imode = 0666;
qcmd->znotify = NULL;
qcmd->cbytes = -1;
qcmd->zcmd = NULL;
qcmd->ipos = 0;
/* Handle hangup commands specially. If it's just "H", return
the command 'H' to indicate a hangup request. If it's "HY"
return 'Y' and if it's "HN" return 'N'. */
if (qcmd->bcmd == 'H')
{
if (z[1] != '\0')
{
if (z[1] == 'Y')
qcmd->bcmd = 'Y';
else if (z[1] == 'N')
qcmd->bcmd = 'N';
else
return FALSE;
}
return TRUE;
}
if (qcmd->bcmd == 'P')
return TRUE;
if (z[1] != '\0')
return FALSE;
z = strtok ((char *) NULL, " \t\n");
if (z == NULL)
return FALSE;
qcmd->zfrom = z;
z = strtok ((char *) NULL, " \t\n");
if (z == NULL)
return FALSE;
qcmd->zto = z;
z = strtok ((char *) NULL, " \t\n");
if (z == NULL)
return FALSE;
qcmd->zuser = z;
z = strtok ((char *) NULL, " \t\n");
if (z == NULL || *z != '-')
return FALSE;
qcmd->zoptions = z + 1;
if (qcmd->bcmd == 'X')
{
ulunquote_cmd (qcmd);
return TRUE;
}
if (qcmd->bcmd == 'R')
{
z = strtok ((char *) NULL, " \t\n");
if (z != NULL)
{
if (strcmp (z, "dummy") != 0)
{
/* This may be the maximum number of bytes the remote
system wants to receive, if it using Taylor UUCP size
negotiation. */
qcmd->cbytes = strtol (z, &zend, 0);
if (*zend != '\0')
qcmd->cbytes = -1;
}
else
{
/* This is from an SVR4 system, and may include the
position at which to start sending the file. The
next fields are the mode bits, the remote owner (?),
the remote temporary file name, and finally the
restart position. */
if (strtok ((char *) NULL, " \t\n") != NULL
&& strtok ((char *) NULL, " \t\n") != NULL
&& strtok ((char *) NULL, " \t\n") != NULL)
{
z = strtok ((char *) NULL, " \t\n");
if (z != NULL)
{
qcmd->ipos = strtol (z, &zend, 0);
if (*zend != '\0')
qcmd->ipos = 0;
}
}
}
}
ulunquote_cmd (qcmd);
return TRUE;
}
z = strtok ((char *) NULL, " \t\n");
if (z == NULL)
return FALSE;
qcmd->ztemp = z;
z = strtok ((char *) NULL, " \t\n");
if (z == NULL)
return FALSE;
qcmd->imode = (int) strtol (z, &zend, 0);
if (*zend != '\0')
return FALSE;
/* As a magic special case, if the mode came out as the decimal
values 666 or 777, assume that they actually meant the octal
values. Most systems use a leading zero, but a few do not.
Since both 666 and 777 are greater than the largest legal mode
value, which is 0777 == 511, this hack does not restrict any
legal values. */
if (qcmd->imode == 666)
qcmd->imode = 0666;
else if (qcmd->imode == 777)
qcmd->imode = 0777;
z = strtok ((char *) NULL, " \t\n");
if (qcmd->bcmd == 'E' && z == NULL)
return FALSE;
qcmd->znotify = z;
/* SVR4 UUCP will send the string "dummy" after the notify string
but before the size. I do not know when it sends anything other
than "dummy". Fortunately, it doesn't really hurt to not get the
file size. */
if (z != NULL && strcmp (z, "dummy") == 0)
z = strtok ((char *) NULL, " \t\n");
if (z != NULL)
{
z = strtok ((char *) NULL, " \t\n");
if (z != NULL)
{
qcmd->cbytes = strtol (z, &zend, 0);
if (*zend != '\0')
qcmd->cbytes = -1;
}
else if (qcmd->bcmd == 'E')
return FALSE;
if (z != NULL)
{
z = strtok ((char *) NULL, "");
if (z != NULL)
z[strcspn (z, "\n")] = '\0';
if (qcmd->bcmd == 'E' && z == NULL)
return FALSE;
qcmd->zcmd = z;
}
}
ulunquote_cmd (qcmd);
return TRUE;
}
/* If 'q' appears in the options of a command, unquote all the
relevant strings. */
static void
ulunquote_cmd (qcmd)
struct scmd *qcmd;
{
if (qcmd->zoptions == NULL || strchr (qcmd->zoptions, 'q') == NULL)
return;
if (qcmd->zfrom != NULL)
(void) cescape ((char *) qcmd->zfrom);
if (qcmd->zto != NULL)
(void) cescape ((char *) qcmd->zto);
if (qcmd->zuser != NULL)
(void) cescape ((char *) qcmd->zuser);
if (qcmd->znotify != NULL)
(void) cescape ((char *) qcmd->znotify);
if (qcmd->zcmd != NULL)
(void) cescape ((char *) qcmd->zcmd);
}
|