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>
*
* $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 "ftpc.h"
#include "lib/petsciiconv.h"
#include <string.h>
#include <stdio.h>
@ -271,48 +272,51 @@ senddata(struct ftp_connection *c)
switch(c->state) {
case STATE_SEND_USER:
len = 5 + (u16_t)strlen(ftpc_username()) + 2;
strcpy(uip_appdata, "USER ");
strncpy((char *)uip_appdata + 5, ftpc_username(), uip_mss() - 7);
len = (u16_t)strlen(ftpc_username());
strcpy((char *)uip_appdata + 5 + len, "\r\n");
uip_send(uip_appdata, len + 2 + 5);
strncpy((char *)uip_appdata + 5, ftpc_username(), uip_mss() - 5 - 2);
strcpy((char *)uip_appdata + len - 2, "\r\n");
break;
case STATE_SEND_PASS:
len = 5 + (u16_t)strlen(ftpc_password()) + 2;
strcpy(uip_appdata, "PASS ");
strncpy((char *)uip_appdata + 5, ftpc_password(), uip_mss() - 7);
len = (u16_t)strlen(ftpc_password());
strcpy((char *)uip_appdata + 5 + len, "\r\n");
uip_send(uip_appdata, len + 2 + 5);
strncpy((char *)uip_appdata + 5, ftpc_password(), uip_mss() - 5 - 2);
strcpy((char *)uip_appdata + len - 2, "\r\n");
break;
case STATE_SEND_PORT:
len = sprintf(uip_appdata, "PORT %d,%d,%d,%d,%d,%d\n",
uip_ipaddr_to_quad(&uip_hostaddr),
(c->dataconn.port) >> 8,
(c->dataconn.port) & 0xff);
uip_send(uip_appdata, len);
break;
case STATE_SEND_OPTIONS:
len = (u16_t)strlen(options.commands[c->optionsptr]);
uip_send(options.commands[c->optionsptr], len);
strcpy(uip_appdata, options.commands[c->optionsptr]);
break;
case STATE_SEND_NLST:
uip_send("NLST\r\n", 6);
len = 6;
strcpy(uip_appdata, "NLST\r\n");
break;
case STATE_SEND_RETR:
len = sprintf(uip_appdata, "RETR %s\r\n", c->filename);
uip_send(uip_appdata, len);
break;
case STATE_SEND_CWD:
len = sprintf(uip_appdata, "CWD %s\r\n", c->filename);
uip_send(uip_appdata, len);
break;
case STATE_SEND_CDUP:
uip_send("CDUP\r\n", 6);
len = 6;
strcpy(uip_appdata, "CDUP\r\n");
break;
case STATE_SEND_QUIT:
uip_send("QUIT\r\n", 6);
len = 6;
strcpy(uip_appdata, "QUIT\r\n");
break;
default:
return;
}
petsciiconv_toascii(uip_appdata, len);
uip_send(uip_appdata, len);
}
/*---------------------------------------------------------------------------*/
void
@ -397,7 +401,8 @@ ftpc_appcall(void *state)
if(t == ISO_nl) {
d->filename[d->filenameptr] = 0;
ftpc_list_file(d->filename);
petsciiconv_topetscii(d->filename, d->filenameptr);
ftpc_list_file(d->filename);
d->filenameptr = 0;
}
@ -449,6 +454,7 @@ ftpc_get(void *conn, char *filename)
}
strncpy(c->filename, filename, sizeof(c->filename));
petsciiconv_toascii(c->filename, sizeof(c->filename));
c->state = STATE_SEND_RETR;
c->dataconn.conntype = CONNTYPE_FILE;