Nucleus Patch

1. Nucleus builds changed the source file names to have a wolfssh_
   prefix. Take that into account for misc.c.
2. Change CleanPath to add a delimiter to the input string.
3. Reorganize the WS_GETtime macros to clean up adding specific items
   for Nucleus.
4. Add some typecasting on some sizeof.
5. Some whitespace cleanup, and removing a redundant include.
pull/647/head
John Safranek 2023-12-27 18:57:35 -08:00
parent 60a29602e5
commit afac19dc93
4 changed files with 51 additions and 13 deletions

View File

@ -54,7 +54,11 @@
#include <wolfssh/misc.h> #include <wolfssh/misc.h>
#else #else
#define WOLFSSH_MISC_INCLUDED #define WOLFSSH_MISC_INCLUDED
#if defined(WOLFSSL_NUCLEUS)
#include "src/wolfssh_misc.c"
#else
#include "src/misc.c" #include "src/misc.c"
#endif
#endif #endif
@ -13849,6 +13853,8 @@ int wolfSSH_CleanPath(WOLFSSH* ssh, char* in)
if (path[sz - 1] == ':') { if (path[sz - 1] == ':') {
path[sz] = WS_DELIM; path[sz] = WS_DELIM;
path[sz + 1] = '\0'; path[sz + 1] = '\0';
in[sz] = WS_DELIM;
in[sz + 1] = '\0';
} }
/* clean up any multiple drive listed i.e. A:/A: */ /* clean up any multiple drive listed i.e. A:/A: */

View File

@ -39,7 +39,11 @@
#include <wolfssh/misc.h> #include <wolfssh/misc.h>
#else #else
#define WOLFSSH_MISC_INCLUDED #define WOLFSSH_MISC_INCLUDED
#if defined(WOLFSSL_NUCLEUS)
#include "src/wolfssh_misc.c"
#else
#include "src/misc.c" #include "src/misc.c"
#endif
#endif #endif
#ifdef HAVE_FIPS #ifdef HAVE_FIPS

View File

@ -34,7 +34,11 @@
#include <wolfssh/misc.h> #include <wolfssh/misc.h>
#else #else
#define WOLFSSH_MISC_INCLUDED #define WOLFSSH_MISC_INCLUDED
#if defined(WOLFSSL_NUCLEUS)
#include "src/wolfssh_misc.c"
#else
#include "src/misc.c" #include "src/misc.c"
#endif
#endif #endif
/* for XGMTIME if defined */ /* for XGMTIME if defined */
@ -2731,6 +2735,15 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
ret = WS_NEXT_ERROR; ret = WS_NEXT_ERROR;
} }
if (special) {
sz = WSTRLEN(out->fName);
if ((out->fName[sz - 1] == '/') || (out->fName[sz - 1] == WS_DELIM)) {
out->fName[sz - 1] = '\0';
out->fSz--;
}
}
/* Use attributes and fName to create long name */ /* Use attributes and fName to create long name */
if (SFTP_CreateLongName(out) != WS_SUCCESS) { if (SFTP_CreateLongName(out) != WS_SUCCESS) {
WLOG(WS_LOG_DEBUG, "Error creating long name for %s", out->fName); WLOG(WS_LOG_DEBUG, "Error creating long name for %s", out->fName);
@ -4271,12 +4284,22 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
#ifndef NO_WOLFSSH_MKTIME #ifndef NO_WOLFSSH_MKTIME
#define WS_GETDAY(d) ((d) & 0x001f) #define WS_GETDAY(d) ((d) & 0x001f)
#define WS_GETMON(d) (((d) >> 5) & 0x000f) #define _GETMON(d) (((d) >> 5) & 0x000f)
/* number of years since 1900. year + 1980 - 1900 */ /* number of years since 1900. year + 1980 - 1900 */
#define WS_GETYEAR(d) ((((d) >> 9) & 0x007f) + 80) #define WS_GETYEAR(d) ((((d) >> 9) & 0x007f) + 80)
#define WS_GETHOUR(t) (((t) >> 11) & 0x001f) #define _GETHOUR(t) (((t) >> 11) & 0x001f)
#define WS_GETMIN(t) (((t) >> 5 ) & 0x003f) #define WS_GETMIN(t) (((t) >> 5 ) & 0x003f)
#define WS_GETSEC(t) (((t) << 1 ) & 0x003f) #define WS_GETSEC(t) (((t) << 1 ) & 0x003f)
#ifdef WOLFSSL_NUCLEUS
/* mktime() expects month from 0 to 11. Nucleus months
* are saved as 1 to 12. Hence 1 is being deducted to
* make it compatible with Unix time stamp. */
#define WS_GETMON(d) (_GETMON(d) - 5)
#define WS_GETHOUR(t) (_GETHOUR(t) - 1)
#else
#define WS_GETMON(d) _GETMON(d)
#define WS_GETHOUR(t) _GETHOUR(t)
#endif
/* convert nucleus date and time shorts to word32 /* convert nucleus date and time shorts to word32
* returns results in Unix time stamp */ * returns results in Unix time stamp */
@ -7159,7 +7182,6 @@ int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
ret = wolfSSH_worker(ssh, NULL); ret = wolfSSH_worker(ssh, NULL);
continue; /* skip past rest and send more */ continue; /* skip past rest and send more */
} }
if (state->sentSz <= 0) { if (state->sentSz <= 0) {
ssh->error = state->sentSz; ssh->error = state->sentSz;
ret = WS_FATAL_ERROR; ret = WS_FATAL_ERROR;
@ -8901,7 +8923,6 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
} }
} }
/* called when wolfSSH_free() is called /* called when wolfSSH_free() is called
* return WS_SUCCESS on success */ * return WS_SUCCESS on success */
int wolfSSH_SFTP_free(WOLFSSH* ssh) int wolfSSH_SFTP_free(WOLFSSH* ssh)
@ -8950,7 +8971,6 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
return WS_SUCCESS; return WS_SUCCESS;
} }
#ifdef WOLFSSH_SHOW_SIZES #ifdef WOLFSSH_SHOW_SIZES
void wolfSSH_SFTP_ShowSizes(void) void wolfSSH_SFTP_ShowSizes(void)

View File

@ -33,6 +33,10 @@
#include <wolfssh/settings.h> #include <wolfssh/settings.h>
#include <wolfssh/log.h> #include <wolfssh/log.h>
#ifdef WOLFSSL_NUCLEUS
#include "os/networking/utils/util_tp.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -105,14 +109,16 @@ extern "C" {
#define WFILE int #define WFILE int
WOLFSSH_API int wfopen(WFILE**, const char*, const char*); WOLFSSH_API int wfopen(WFILE**, const char*, const char*);
#define WFOPEN(fs, f,fn,m) wfopen((f),(fn),(m)) #define WFOPEN(fs,f,fn,m) wfopen((f),(fn),(m))
#define WFCLOSE(fs,f) NU_Close(*(f)) #define WFCLOSE(fs,f) NU_Close(*(f))
#define WFWRITE(fs,b,x,s,f) ((s) != 0)? NU_Write(*(f),(const CHAR*)(b),(s)): 0 #define WFWRITE(fs,b,x,s,f) \
(((s) != 0) ? NU_Write(*(f),(const CHAR*)(b),(s)) : 0)
#define WFREAD(fs,b,x,s,f) NU_Read(*(f),(CHAR*)(b),(s)) #define WFREAD(fs,b,x,s,f) NU_Read(*(f),(CHAR*)(b),(s))
#define WFSEEK(fs,s,o,w) NU_Seek(*(s),(o),(w)) #define WFSEEK(fs,s,o,w) NU_Seek(*(s),(o),(w))
#define WFTELL(fs,s) NU_Seek(*(s), 0, PSEEK_CUR) #define WFTELL(fs,s) NU_Seek(*(s), 0, PSEEK_CUR)
#define WREWIND(fs,s) NU_Seek(*(s), 0, PSEEK_SET) #define WREWIND(fs,s) NU_Seek(*(s), 0, PSEEK_SET)
#define WSEEK_END PSEEK_END #define WSEEK_END PSEEK_END
#define WBADFILE NULL
#define WS_DELIM '\\' #define WS_DELIM '\\'
#define WOLFSSH_O_RDWR PO_RDWR #define WOLFSSH_O_RDWR PO_RDWR
@ -561,6 +567,9 @@ extern "C" {
#elif defined(WOLFSSH_ZEPHYR) #elif defined(WOLFSSH_ZEPHYR)
#define WTIME time #define WTIME time
#define WLOCALTIME(c,r) (gmtime_r((c),(r))!=NULL) #define WLOCALTIME(c,r) (gmtime_r((c),(r))!=NULL)
#elif defined(WOLFSSL_NUCLEUS)
#define WTIME time
#define WLOCALTIME(c,r) (localtime_s((c),(r))!=NULL)
#else #else
#define WTIME time #define WTIME time
#define WLOCALTIME(c,r) (localtime_r((c),(r))!=NULL) #define WLOCALTIME(c,r) (localtime_r((c),(r))!=NULL)
@ -756,7 +765,7 @@ extern "C" {
if (NU_Get_Attributes(&atrib, dir) == NU_SUCCESS) { if (NU_Get_Attributes(&atrib, dir) == NU_SUCCESS) {
if (atrib & ADIRENT) { if (atrib & ADIRENT) {
if (tmp[idx-1] != WS_DELIM) { if (tmp[idx-1] != WS_DELIM) {
if (idx + 2 > sizeof(tmp)) { if (idx + 2 > (int)sizeof(tmp)) {
/* not enough space */ /* not enough space */
return -1; return -1;
} }
@ -768,7 +777,7 @@ extern "C" {
} }
if (tmp[idx - 1] == WS_DELIM) { if (tmp[idx - 1] == WS_DELIM) {
if (idx + 1 > sizeof(tmp)) { if (idx + 1 > (int)sizeof(tmp)) {
/* not enough space */ /* not enough space */
return -1; return -1;
} }
@ -1316,7 +1325,6 @@ extern "C" {
#include <unistd.h> /* used for rmdir */ #include <unistd.h> /* used for rmdir */
#include <sys/stat.h> /* used for mkdir, stat, and lstat */ #include <sys/stat.h> /* used for mkdir, stat, and lstat */
#include <stdio.h> /* used for remove and rename */ #include <stdio.h> /* used for remove and rename */
#include <dirent.h> /* used for opening directory and reading */
#define WSTAT_T struct stat #define WSTAT_T struct stat
#define WRMDIR(fs,d) rmdir((d)) #define WRMDIR(fs,d) rmdir((d))