Ejemplo n.º 1
0
/*
 * RFC3617 handling of TFTP URIs:
 *
 *    tftpURI         = "tftp://" host "/" file [ mode ]
 *    mode            = ";"  "mode=" ( "netascii" / "octet" )
 *    file            = *( unreserved / escaped )
 *    host            = <as specified by RFC 2732>
 *    unreserved      = <as specified in RFC 2396>
 *    escaped         = <as specified in RFC 2396>
 *
 * We are cheating a little bit by allowing any mode as specified in the
 * modes table defined earlier on in this file and mapping it on the real
 * mode.
 */
static void
urihandling(char *URI)
{
	char	uri[ARG_MAX];
	char	*host = NULL;
	char	*path = NULL;
	char	*opts = NULL;
	const char *tmode = "octet";
	char	*s;
	char	line[MAXLINE];
	int	i;

	strncpy(uri, URI, ARG_MAX);
	host = uri + 7;

	if ((s = strchr(host, '/')) == NULL) {
		fprintf(stderr,
		    "Invalid URI: Couldn't find / after hostname\n");
		exit(1);
	}
	*s = '\0';
	path = s + 1;

	if ((s = strchr(path, ';')) != NULL) {
		*s = '\0';
		opts = s + 1;

		if (strncmp(opts, "mode=", 5) == 0) {
			tmode = opts;
			tmode += 5;

			for (i = 0; modes[i].m_name != NULL; i++) {
				if (strcmp(modes[i].m_name, tmode) == 0)
					break;
			}
			if (modes[i].m_name == NULL) {
				fprintf(stderr, "Invalid mode: '%s'\n", mode);
				exit(1);
			}
			settftpmode(modes[i].m_mode);
		}
	} else {
		settftpmode("octet");
	}

	setpeer0(host, NULL);

	sprintf(line, "get %s", path);
	makeargv(line);
	get(margc, margv);
}
Ejemplo n.º 2
0
static void
modecmd(int argc, char *argv[])
{
	struct modes *p;
	const char *sep;

	if (argc < 2) {
		printf("Using %s mode to transfer files.\n", mode);
		return;
	}
	if (argc == 2) {
		for (p = modes; p->m_name; p++)
			if (strcmp(argv[1], p->m_name) == 0)
				break;
		if (p->m_name) {
			settftpmode(p->m_mode);
			return;
		}
		printf("%s: unknown mode\n", argv[1]);
		/* drop through and print usage message */
	}

	printf("usage: %s [", argv[0]);
	sep = " ";
	for (p = modes; p->m_name != NULL; p++) {
		printf("%s%s", sep, p->m_name);
		if (*sep == ' ')
			sep = " | ";
	}
	printf(" ]\n");
	return;
}
Ejemplo n.º 3
0
/* ARGSUSED */
void
setascii(int argc, char *argv[])
{
	settftpmode("netascii");
}
Ejemplo n.º 4
0
/* ARGSUSED */
void
setbinary(int argc, char *argv[])
{
	settftpmode("octet");
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: 274914765/C
void setascii (int argc, char *argv[])
{
    (void) argc;
    (void) argv;                /* Quiet unused warning */
    settftpmode (MODE_NETASCII);
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: 274914765/C
void setbinary (int argc, char *argv[])
{
    (void) argc;
    (void) argv;                /* Quiet unused warning */
    settftpmode (MODE_OCTET);
}