Skip to content

Commit 4f9e6b5

Browse files
remove some trailing white space and initialize get current drive buffer
1 parent 7067b20 commit 4f9e6b5

File tree

4 files changed

+48
-35
lines changed

4 files changed

+48
-35
lines changed

ide/mplabx/wolfssh.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* wolfssh.c
22
*
3-
* Copyright (C) 2014-2016 wolfSSL Inc.
3+
* Copyright (C) 2014-2025 wolfSSL Inc.
44
*
55
* This file is part of wolfSSH.
66
*
@@ -109,11 +109,16 @@ PwMapList pwMapList;
109109

110110
static const char echoserverBanner[] = "wolfSSH Example Echo Server\n";
111111

112+
113+
/* These are example user:password strings. To update for an admin user
114+
* a string could be added to the list with something like "admin:admin123\n"
115+
*/
112116
static const char samplePasswordBuffer[] =
113117
"jill:upthehill\n"
114118
"jack:fetchapail\n";
115119

116120

121+
/* These are example public key authentication options. */
117122
static const char samplePublicKeyEccBuffer[] =
118123
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA"
119124
"BBBNkI5JTP6D0lF42tbxX19cE87hztUS6FSDoGvPfiU0CgeNSbI+aFdKIzTP5CQEJSvm25"
@@ -386,7 +391,8 @@ static byte find_char(const byte* str, const byte* buf, word32 bufSz)
386391
}
387392

388393

389-
#if 1
394+
#if 0
395+
/* redirection of logging message to SYS_CONSOLE_PRINT instead of printf */
390396
static void logCb(enum wolfSSH_LogLevel lvl, const char *const msg)
391397
{
392398
if ( wolfSSH_LogEnabled()
@@ -407,23 +413,25 @@ void APP_Initialize ( void )
407413
{
408414
appData.state = APP_SSH_CTX_INIT;
409415
wolfSSH_Init();
410-
#if 1
416+
#if 0
417+
/* Used to enable debug messages and set logging callback */
411418
SYS_CONSOLE_PRINT("Turning on wolfSSH debugging\n\r");
412419
wolfSSH_Debugging_ON();
413420
wolfSSH_SetLoggingCb(logCb);
414421
#endif
415422
}
416423

417424
#ifndef NO_FILESYSTEM
418-
#define APP_MOUNT_NAME "/mnt/myDrive1/"
419-
#define APP_DEVICE_NAME "/dev/nvma1"
420-
#ifdef SYS_FS_LFS_MAX_SS
421-
#define APP_FS_TYPE LITTLEFS
422-
#elif defined(SYS_FS_FAT_MAX_SS)
423-
#define APP_FS_TYPE FAT
424-
#else
425-
#error untested file system setup
426-
#endif
425+
426+
#define APP_MOUNT_NAME "/mnt/myDrive1/"
427+
#define APP_DEVICE_NAME "/dev/nvma1"
428+
#ifdef SYS_FS_LFS_MAX_SS
429+
#define APP_FS_TYPE LITTLEFS
430+
#elif defined(SYS_FS_FAT_MAX_SS)
431+
#define APP_FS_TYPE FAT
432+
#else
433+
#error untested file system setup
434+
#endif
427435

428436
static void CreateTestFile(void)
429437
{

src/port.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
124124
defined(FREESCALE_MQX) || defined(WOLFSSH_ZEPHYR)
125125

126126
/* This is current inline in the source. */
127+
127128
#elif defined(MICROCHIP_MPLAB_HARMONY)
128129
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,
129130
const unsigned int* shortOffset)
@@ -149,7 +150,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
149150

150151
return ret;
151152
}
152-
153+
153154
#elif defined(WOLFSSH_LOCAL_PREAD_PWRITE)
154155

155156
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,

src/wolfsftp.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,7 +3520,6 @@ int wolfSSH_SFTP_RecvCloseDir(WOLFSSH* ssh, byte* handle, word32 handleSz)
35203520
}
35213521
#endif /* NO_WOLFSSH_DIR */
35223522

3523-
35243523
/* Handles packet to write a file
35253524
*
35263525
* returns WS_SUCCESS on success
@@ -3589,7 +3588,6 @@ int wolfSSH_SFTP_RecvWrite(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
35893588
ret = WS_INVALID_STATE_E;
35903589
}
35913590
else {
3592-
WLOG(WS_LOG_SFTP, "Wrote %d bytes to file", ret);
35933591
ret = WS_SUCCESS;
35943592
}
35953593
}
@@ -3792,7 +3790,6 @@ int wolfSSH_SFTP_RecvRead(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
37923790
if (outSz > sz) {
37933791
/* need to increase buffer size for holding status packet */
37943792
WFREE(out, ssh->ctx->heap, DYNTYPE_BUFFER);
3795-
WLOG(WS_LOG_SFTP, "Allocating a new buffer of size %d", outSz);
37963793
out = (byte*)WMALLOC(outSz, ssh->ctx->heap, DYNTYPE_BUFFER);
37973794
if (out == NULL) {
37983795
return WS_MEMORY_E;
@@ -4966,15 +4963,15 @@ int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
49664963
return WS_SUCCESS;
49674964
}
49684965

4966+
49694967
static int SFTP_GetAttributesHelper(WS_SFTP_FILEATRB* atr, const char* fName)
49704968
{
49714969
WSTAT_T stats;
49724970
SYS_FS_RESULT res;
49734971
char buffer[255];
49744972

4975-
WMEMSET(&stats, 0, sizeof(WSTAT_T));
49764973
WMEMSET(atr, 0, sizeof(WS_SFTP_FILEATRB));
4977-
4974+
WMEMSET(buffer, 0, sizeof(buffer));
49784975
res = SYS_FS_CurrentDriveGet(buffer);
49794976
if (res == SYS_FS_RES_SUCCESS) {
49804977
if (WSTRCMP(fName, buffer) == 0) {
@@ -5336,9 +5333,6 @@ int wolfSSH_SFTP_RecvLSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
53365333
ret = WS_FATAL_ERROR;
53375334
}
53385335

5339-
5340-
WLOG(WS_LOG_SFTP, "SFTP default path = %s name after get and clean = %s",
5341-
ssh->sftpDefaultPath, name);
53425336
/* try to get file attributes and send back to client */
53435337
if (ret == WS_SUCCESS) {
53445338
WMEMSET((byte*)&atr, 0, sizeof(WS_SFTP_FILEATRB));
@@ -9072,8 +9066,11 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
90729066
}
90739067
}
90749068
}
9075-
//ret = WFOPEN(ssh->fs, &state->fl, from, "rb");
9069+
#if defined(MICROCHIP_MPLAB_HARMONY)
90769070
ret = WFOPEN(ssh->fs, &state->fl, from, WOLFSSH_O_RDONLY);
9071+
#else
9072+
ret = WFOPEN(ssh->fs, &state->fl, from, "rb");
9073+
#endif
90779074
if (ret != 0) {
90789075
WLOG(WS_LOG_SFTP, "Unable to open input file");
90799076
ssh->error = WS_SFTP_FILE_DNE;
@@ -9224,7 +9221,7 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
92249221
/* go through and free handles and make sure files are closed */
92259222
while (cur != NULL) {
92269223
#ifdef MICROCHIP_MPLAB_HARMONY
9227-
//@TODO #warning todo clean handles
9224+
WFCLOSE(ssh->fs, ((WFILE*)cur->handle));
92289225
#else
92299226
WCLOSE(ssh->fs, *((WFD*)cur->handle));
92309227
#endif
@@ -9234,9 +9231,8 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
92349231
}
92359232
cur = ssh->handleList;
92369233
}
9237-
9234+
92389235
return WS_SUCCESS;
9239-
92409236
}
92419237
#endif
92429238

@@ -9245,7 +9241,7 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
92459241
int wolfSSH_SFTP_free(WOLFSSH* ssh)
92469242
{
92479243
int ret = WS_SUCCESS;
9248-
9244+
92499245
WOLFSSH_UNUSED(ssh);
92509246
#ifdef WOLFSSH_STOREHANDLE
92519247
ret = SFTP_FreeHandles(ssh);

wolfssh/port.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ extern "C" {
394394
#include <stdio.h>
395395

396396
#include "system/fs/sys_fs.h"
397-
397+
398398
#define WFFLUSH(s) SYS_FS_FileSync((s))
399399

400400
#define WFILE SYS_FS_HANDLE
@@ -451,7 +451,7 @@ extern "C" {
451451
#ifdef WOLFSSL_VXWORKS
452452
#define WUTIMES(f,t) (WS_SUCCESS)
453453
#elif defined(USE_WINDOWS_API)
454-
#include <sys/utime.h>
454+
#include <sys/utime.h>
455455
#else
456456
#define WUTIMES(f,t) utimes((f),(t))
457457
#endif
@@ -1385,14 +1385,23 @@ extern "C" {
13851385

13861386
static inline int wStat(const char* path, WSTAT_T* stat)
13871387
{
1388-
int ret = SYS_FS_FileStat(path, stat);
1389-
1390-
WLOG(WS_LOG_SFTP, "Return from SYS_FS_fileStat [%s] = %d, expecting %d",
1388+
int ret;
1389+
WMEMSET(stat, 0, sizeof(WSTAT_T));
1390+
ret = SYS_FS_FileStat(path, stat);
1391+
1392+
if (ret != SYS_FS_RES_SUCCESS) {
1393+
WLOG(WS_LOG_SFTP,
1394+
"Return from SYS_FS_fileStat [%s] = %d, expecting %d",
13911395
path, ret, SYS_FS_RES_SUCCESS);
1392-
WLOG(WS_LOG_SFTP, "SYS error reason = %d", SYS_FS_Error());
1396+
WLOG(WS_LOG_SFTP, "SYS error reason = %d", SYS_FS_Error());
1397+
return -1;
1398+
}
1399+
else {
1400+
return 0;
1401+
}
13931402
return 0;
13941403
}
1395-
1404+
13961405
static inline char *ff_getcwd(char *r, int rSz)
13971406
{
13981407
SYS_FS_RESULT ret;
@@ -1413,8 +1422,7 @@ extern "C" {
14131422
#define WOLFSSH_O_EXCL 0
14141423

14151424
/* Our "file descriptor" wrapper */
1416-
1417-
//@TODO maybe this should be int or something to handle DIR to?
1425+
14181426
#define WFD SYS_FS_HANDLE
14191427
int wPwrite(WFD, unsigned char*, unsigned int, const unsigned int*);
14201428
int wPread(WFD, unsigned char*, unsigned int, const unsigned int*);

0 commit comments

Comments
 (0)