Skip to content

Commit d74c942

Browse files
refactor SFTP to use NoticeError
1 parent af45bc3 commit d74c942

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

examples/sftpclient/sftpclient.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ static int doCmds(func_args* args)
11191119
/* alternate main loop for the autopilot get/receive */
11201120
static int doAutopilot(int cmd, char* local, char* remote)
11211121
{
1122-
int err;
1122+
int err = 0;
11231123
int ret = WS_SUCCESS;
11241124
char fullpath[128] = ".";
11251125
WS_SFTPNAME* name = NULL;
@@ -1156,6 +1156,12 @@ static int doAutopilot(int cmd, char* local, char* remote)
11561156
}
11571157

11581158
do {
1159+
if (err == WS_REKEYING) { /* handle rekeying state */
1160+
do {
1161+
ret = wolfSSH_worker(ssh, NULL);
1162+
} while (ret == WS_REKEYING);
1163+
}
1164+
11591165
if (cmd == AUTOPILOT_PUT) {
11601166
ret = wolfSSH_SFTP_Put(ssh, local, fullpath, 0, NULL);
11611167
}

src/ssh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ int wolfSSH_stream_send(WOLFSSH* ssh, byte* buf, word32 bufSz)
12011201

12021202
if (ssh->isKeying) {
12031203
ssh->error = WS_REKEYING;
1204-
return WS_REKEYING;
1204+
return WS_FATAL_ERROR;
12051205
}
12061206

12071207
bytesTxd = SendChannelData(ssh, ssh->channelList->channel, buf, bufSz);

src/wolfsftp.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,11 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
14181418
ret = wolfSSH_SFTP_buffer_read(ssh, &state->buffer,
14191419
state->buffer.sz);
14201420
if (ret < 0) {
1421-
if (!NoticeError(ssh)) {
1421+
if (NoticeError(ssh)) {
1422+
/* keep state for returning to */
1423+
ret = WS_FATAL_ERROR;
1424+
}
1425+
else {
14221426
wolfSSH_SFTP_ClearState(ssh, STATE_ID_RECV);
14231427
}
14241428
return ret;
@@ -7452,8 +7456,7 @@ int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
74527456
/* send header and type specific data */
74537457
ret = wolfSSH_SFTP_buffer_send(ssh, &state->buffer);
74547458
if (ret < 0) {
7455-
if (ssh->error == WS_WANT_READ ||
7456-
ssh->error == WS_WANT_WRITE) {
7459+
if (NoticeError(ssh)) {
74577460
return WS_FATAL_ERROR;
74587461
}
74597462
state->state = STATE_SEND_WRITE_CLEANUP;
@@ -7465,12 +7468,8 @@ int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
74657468
case STATE_SEND_WRITE_SEND_BODY:
74667469
WLOG(WS_LOG_SFTP, "SFTP SEND_WRITE STATE: SEND_BODY");
74677470
state->sentSz = wolfSSH_stream_send(ssh, in, inSz);
7468-
if (state->sentSz == WS_WINDOW_FULL ||
7469-
state->sentSz == WS_REKEYING ||
7470-
state->sentSz == WS_WANT_READ ||
7471-
state->sentSz == WS_WANT_WRITE) {
7472-
ret = wolfSSH_worker(ssh, NULL);
7473-
continue; /* skip past rest and send more */
7471+
if (NoticeError(ssh)) {
7472+
return WS_FATAL_ERROR;
74747473
}
74757474
if (state->sentSz <= 0) {
74767475
ssh->error = state->sentSz;
@@ -7496,8 +7495,7 @@ int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
74967495
state->maxSz = SFTP_GetHeader(ssh, &state->reqId, &type,
74977496
&state->buffer);
74987497
if (state->maxSz <= 0) {
7499-
if (ssh->error == WS_WANT_READ ||
7500-
ssh->error == WS_WANT_WRITE) {
7498+
if (NoticeError(ssh)) {
75017499
return WS_FATAL_ERROR;
75027500
}
75037501
ssh->error = WS_SFTP_BAD_HEADER;
@@ -9167,10 +9165,9 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
91679165
state->handle, state->handleSz, state->pOfst,
91689166
state->r, state->rSz);
91699167
if (sz <= 0) {
9170-
if (ssh->error == WS_WANT_READ ||
9171-
ssh->error == WS_WANT_WRITE ||
9172-
ssh->error == WS_WINDOW_FULL)
9168+
if (NoticeError(ssh)) {
91739169
return WS_FATAL_ERROR;
9170+
}
91749171
}
91759172
else {
91769173
AddAssign64(state->pOfst, sz);

0 commit comments

Comments
 (0)