Added PETSCII support to the FTP client. It seems reasonable to do this in ftpc.c (instead of ftp.c) as all command connection strings are given in PETSCII in the C source.

This commit is contained in:
oliverschmidt 2010-10-19 22:30:13 +00:00
parent 105fe0b5df
commit fd18646d12

View file

@ -30,10 +30,11 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: ftpc.c,v 1.5 2010/10/19 18:29:03 adamdunkels Exp $ * $Id: ftpc.c,v 1.6 2010/10/19 22:30:13 oliverschmidt Exp $
*/ */
#include "contiki.h" #include "contiki.h"
#include "ftpc.h" #include "ftpc.h"
#include "lib/petsciiconv.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -271,48 +272,51 @@ senddata(struct ftp_connection *c)
switch(c->state) { switch(c->state) {
case STATE_SEND_USER: case STATE_SEND_USER:
len = 5 + (u16_t)strlen(ftpc_username()) + 2;
strcpy(uip_appdata, "USER "); strcpy(uip_appdata, "USER ");
strncpy((char *)uip_appdata + 5, ftpc_username(), uip_mss() - 7); strncpy((char *)uip_appdata + 5, ftpc_username(), uip_mss() - 5 - 2);
len = (u16_t)strlen(ftpc_username()); strcpy((char *)uip_appdata + len - 2, "\r\n");
strcpy((char *)uip_appdata + 5 + len, "\r\n");
uip_send(uip_appdata, len + 2 + 5);
break; break;
case STATE_SEND_PASS: case STATE_SEND_PASS:
len = 5 + (u16_t)strlen(ftpc_password()) + 2;
strcpy(uip_appdata, "PASS "); strcpy(uip_appdata, "PASS ");
strncpy((char *)uip_appdata + 5, ftpc_password(), uip_mss() - 7); strncpy((char *)uip_appdata + 5, ftpc_password(), uip_mss() - 5 - 2);
len = (u16_t)strlen(ftpc_password()); strcpy((char *)uip_appdata + len - 2, "\r\n");
strcpy((char *)uip_appdata + 5 + len, "\r\n");
uip_send(uip_appdata, len + 2 + 5);
break; break;
case STATE_SEND_PORT: case STATE_SEND_PORT:
len = sprintf(uip_appdata, "PORT %d,%d,%d,%d,%d,%d\n", len = sprintf(uip_appdata, "PORT %d,%d,%d,%d,%d,%d\n",
uip_ipaddr_to_quad(&uip_hostaddr), uip_ipaddr_to_quad(&uip_hostaddr),
(c->dataconn.port) >> 8, (c->dataconn.port) >> 8,
(c->dataconn.port) & 0xff); (c->dataconn.port) & 0xff);
uip_send(uip_appdata, len);
break; break;
case STATE_SEND_OPTIONS: case STATE_SEND_OPTIONS:
len = (u16_t)strlen(options.commands[c->optionsptr]); len = (u16_t)strlen(options.commands[c->optionsptr]);
uip_send(options.commands[c->optionsptr], len); strcpy(uip_appdata, options.commands[c->optionsptr]);
break; break;
case STATE_SEND_NLST: case STATE_SEND_NLST:
uip_send("NLST\r\n", 6); len = 6;
strcpy(uip_appdata, "NLST\r\n");
break; break;
case STATE_SEND_RETR: case STATE_SEND_RETR:
len = sprintf(uip_appdata, "RETR %s\r\n", c->filename); len = sprintf(uip_appdata, "RETR %s\r\n", c->filename);
uip_send(uip_appdata, len);
break; break;
case STATE_SEND_CWD: case STATE_SEND_CWD:
len = sprintf(uip_appdata, "CWD %s\r\n", c->filename); len = sprintf(uip_appdata, "CWD %s\r\n", c->filename);
uip_send(uip_appdata, len);
break; break;
case STATE_SEND_CDUP: case STATE_SEND_CDUP:
uip_send("CDUP\r\n", 6); len = 6;
strcpy(uip_appdata, "CDUP\r\n");
break; break;
case STATE_SEND_QUIT: case STATE_SEND_QUIT:
uip_send("QUIT\r\n", 6); len = 6;
strcpy(uip_appdata, "QUIT\r\n");
break; break;
default:
return;
} }
petsciiconv_toascii(uip_appdata, len);
uip_send(uip_appdata, len);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -397,6 +401,7 @@ ftpc_appcall(void *state)
if(t == ISO_nl) { if(t == ISO_nl) {
d->filename[d->filenameptr] = 0; d->filename[d->filenameptr] = 0;
petsciiconv_topetscii(d->filename, d->filenameptr);
ftpc_list_file(d->filename); ftpc_list_file(d->filename);
d->filenameptr = 0; d->filenameptr = 0;
} }
@ -449,6 +454,7 @@ ftpc_get(void *conn, char *filename)
} }
strncpy(c->filename, filename, sizeof(c->filename)); strncpy(c->filename, filename, sizeof(c->filename));
petsciiconv_toascii(c->filename, sizeof(c->filename));
c->state = STATE_SEND_RETR; c->state = STATE_SEND_RETR;
c->dataconn.conntype = CONNTYPE_FILE; c->dataconn.conntype = CONNTYPE_FILE;