Browse Source

pull out common function

pull/30/head
Philipp Riederer 2 years ago
parent
commit
127bfdfef5
  1. 49
      ftpd.c

49
ftpd.c

@ -373,6 +373,20 @@ static void ftpd_dataclose(struct tcp_pcb *pcb, struct ftpd_datastate *fsd)
tcp_close(pcb); tcp_close(pcb);
} }
static void close_with_message(struct ftpd_datastate *fsd, struct tcp_pcb *pcb, char* msg) {
struct ftpd_msgstate *fsm;
struct tcp_pcb *msgpcb;
fsm = fsd->msgfs;
msgpcb = fsd->msgpcb;
ftpd_dataclose(pcb, fsd);
fsm->datapcb = NULL;
fsm->datafs = NULL;
fsm->state = FTPD_IDLE;
send_msg(msgpcb, fsm, msg);
}
static void send_data(struct tcp_pcb *pcb, struct ftpd_datastate *fsd) static void send_data(struct tcp_pcb *pcb, struct ftpd_datastate *fsd)
{ {
err_t err; err_t err;
@ -437,21 +451,11 @@ static void send_file(struct ftpd_datastate *fsd, struct tcp_pcb *pcb)
sfifo_write(&fsd->fifo, buffer, len); sfifo_write(&fsd->fifo, buffer, len);
send_data(pcb, fsd); send_data(pcb, fsd);
} else { } else {
struct ftpd_msgstate *fsm;
struct tcp_pcb *msgpcb;
if (sfifo_used(&fsd->fifo) > 0) { if (sfifo_used(&fsd->fifo) > 0) {
send_data(pcb, fsd); send_data(pcb, fsd);
return; return;
} }
fsm = fsd->msgfs; close_with_message(fsd, pcb, msg226);
msgpcb = fsd->msgpcb;
ftpd_dataclose(pcb, fsd);
fsm->datapcb = NULL;
fsm->datafs = NULL;
fsm->state = FTPD_IDLE;
send_msg(msgpcb, fsm, msg226);
return; return;
} }
} }
@ -500,23 +504,14 @@ static void send_next_directory(struct ftpd_datastate *fsd, struct tcp_pcb *pcb,
fsd->vfs_dirent = NULL; fsd->vfs_dirent = NULL;
} }
} else { } else {
struct ftpd_msgstate *fsm;
struct tcp_pcb *msgpcb;
if (sfifo_used(&fsd->fifo) > 0) { if (sfifo_used(&fsd->fifo) > 0) {
send_data(pcb, fsd); send_data(pcb, fsd);
return; return;
} }
fsm = fsd->msgfs;
msgpcb = fsd->msgpcb;
vfs_closedir(fsd->vfs_dir); vfs_closedir(fsd->vfs_dir);
fsd->vfs_dir = NULL; fsd->vfs_dir = NULL;
ftpd_dataclose(pcb, fsd); close_with_message(fsd, pcb, msg226);
fsm->datapcb = NULL;
fsm->datafs = NULL;
fsm->state = FTPD_IDLE;
send_msg(msgpcb, fsm, msg226);
return; return;
} }
} }
@ -567,19 +562,9 @@ static err_t ftpd_datarecv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t
pbuf_free(p); pbuf_free(p);
} }
if (err == ERR_OK && p == NULL) { if (err == ERR_OK && p == NULL) {
struct ftpd_msgstate *fsm;
struct tcp_pcb *msgpcb;
fsm = fsd->msgfs;
msgpcb = fsd->msgpcb;
vfs_close(fsd->vfs_file); vfs_close(fsd->vfs_file);
fsd->vfs_file = NULL; fsd->vfs_file = NULL;
ftpd_dataclose(pcb, fsd); close_with_message(fsd, pcb, msg226);
fsm->datapcb = NULL;
fsm->datafs = NULL;
fsm->state = FTPD_IDLE;
send_msg(msgpcb, fsm, msg226);
} }
return ERR_OK; return ERR_OK;

Loading…
Cancel
Save