Merge pull request #153 from JacobBarthelmeh/sftp-nuc

maintain Nucleus port
pull/160/head
John Safranek 2019-04-09 14:50:21 -07:00 committed by GitHub
commit ff05e7c9cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 14 deletions

View File

@ -85,7 +85,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
#if (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) && \
!defined(NO_WOLFSSH_SERVER)
#if defined(USE_WINDOWS_API)
#if defined(USE_WINDOWS_API) || defined(WOLFSSL_NUCLEUS)
/* This is current inline in the source. */

View File

@ -3380,7 +3380,8 @@ int SFTP_GetAttributes(const char* fileName, WS_SFTP_FILEATRB* atr, byte link,
}
atr->flags |= WOLFSSH_FILEATRB_SIZE;
atr->sz = (word64)stats.fsize;
atr->sz[0] = (word32)(stats.fsize);
atr->sz[1] = (word32)(0);
/* get additional attributes */
{
@ -3443,7 +3444,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WMEMSET(atr, 0, sizeof(WS_SFTP_FILEATRB));
atr->flags |= WOLFSSH_FILEATRB_SIZE;
atr->sz = (word64)stats.fsize;
atr->sz[0] = (word32)(stats.fsize);
atr->sz[1] = (word32)(0);
{
byte atrib = stats.fattribute;

View File

@ -349,7 +349,7 @@ extern "C" {
static inline int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,
const unsigned int* shortOffset)
{
long ofst = ((long)shortOffset[1] << 32) | shortOffset[0];
INT32 ofst = shortOffset[0];
if (ofst > 0) {
NU_Seek(fd, ofst, 0);
}
@ -363,7 +363,7 @@ extern "C" {
static inline int wPread(WFD fd, unsigned char* buf, unsigned int sz,
const unsigned int* shortOffset)
{
long ofst = ((long)shortOffset[1] << 32) | shortOffset[0];
INT32 ofst = shortOffset[0];
if (ofst > 0) {
NU_Seek(fd, ofst, 0);
}

View File

@ -1,4 +1,22 @@
/* test.h */
/* test.h
*
* Copyright (C) 2014-2019 wolfSSL Inc.
*
* This file is part of wolfSSH.
*
* wolfSSH is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
@ -572,26 +590,54 @@ enum {
WS_SELECT_ERROR_READY
};
#ifdef WOLFSSL_NUCLEUS
#define WFD_SET_TYPE FD_SET
#define WFD_SET NU_FD_Set
#define WFD_ZERO NU_FD_Init
#define WFD_ISSET NU_FD_Check
#else
#define WFD_SET_TYPE fd_set
#define WFD_SET FD_SET
#define WFD_ZERO FD_ZERO
#define WFD_ISSET FD_ISSET
#endif
/* returns 1 or greater when something is ready to be read */
static INLINE int wSelect(int nfds, WFD_SET_TYPE* recvfds,
WFD_SET_TYPE *writefds, WFD_SET_TYPE *errfds, struct timeval* timeout)
{
#ifdef WOLFSSL_NUCLEUS
int ret = NU_Select (nfds, recvfds, writefds, errfds,
(UNSIGNED)timeout->tv_sec);
if (ret == NU_SUCCESS) {
return 1;
}
return 0;
#else
return select(nfds, recvfds, writefds, errfds, timeout);
#endif
}
static INLINE int tcp_select(SOCKET_T socketfd, int to_sec)
{
fd_set recvfds, errfds;
WFD_SET_TYPE recvfds, errfds;
int nfds = (int)socketfd + 1;
struct timeval timeout = {(to_sec > 0) ? to_sec : 0, 0};
int result;
FD_ZERO(&recvfds);
FD_SET(socketfd, &recvfds);
FD_ZERO(&errfds);
FD_SET(socketfd, &errfds);
WFD_ZERO(&recvfds);
WFD_SET(socketfd, &recvfds);
WFD_ZERO(&errfds);
WFD_SET(socketfd, &errfds);
result = select(nfds, &recvfds, NULL, &errfds, &timeout);
result = wSelect(nfds, &recvfds, NULL, &errfds, &timeout);
if (result == 0)
return WS_SELECT_TIMEOUT;
else if (result > 0) {
if (FD_ISSET(socketfd, &recvfds))
if (WFD_ISSET(socketfd, &recvfds))
return WS_SELECT_RECV_READY;
else if(FD_ISSET(socketfd, &errfds))
else if(WFD_ISSET(socketfd, &errfds))
return WS_SELECT_ERROR_READY;
}