/* * 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); }
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; }
/* ARGSUSED */ void setascii(int argc, char *argv[]) { settftpmode("netascii"); }
/* ARGSUSED */ void setbinary(int argc, char *argv[]) { settftpmode("octet"); }
void setascii (int argc, char *argv[]) { (void) argc; (void) argv; /* Quiet unused warning */ settftpmode (MODE_NETASCII); }
void setbinary (int argc, char *argv[]) { (void) argc; (void) argv; /* Quiet unused warning */ settftpmode (MODE_OCTET); }