Skip to content

Commit

Permalink
Make wolfSSH_SFTPNAME_readdir overridable when defining WOLFSSH_USER_…
Browse files Browse the repository at this point in the history
…FILESYSTEM and SFTP_Name_readdir.

SFTP_Name_readdir has to be defined as a macro, but it can be defined to expand to its own name if also a function with the same name is defined.

What matters is that it takes 3 arguments:

    1) the filesystem context as first argument;
    2) WDIR* as second argument;
    3) WS_SFTPNAME* as third argument

On successful execution, it returns WS_SUCCESS and the WS_SFTPNAME structure pointed by the third argument will be filled with the relevant info, otherwise a WS_* error code is returned.
  • Loading branch information
falemagn committed Jul 21, 2023
1 parent 87caf4a commit f07aa1b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2870,6 +2870,42 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
return WS_SUCCESS;
}

#elif defined(WOLFSSH_USER_FILESYSTEM) && defined(SFTP_Name_readdir)

/* helper function that gets file information from reading directory.
* Internally uses SFTP_Name_readdir to delegate the work to the User Filesystem.
*
* returns WS_SUCCESS on success
*/
static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
char* dirName)
{
WOLFSSH_UNUSED(dirName);
int res;

if (dir == NULL || ssh == NULL || out == NULL) {
return WS_BAD_ARGUMENT;
}

res = SFTP_Name_readdir(ssh->fs, dir, out);
if (res != WS_SUCCESS) {
return res;
}

if (out->fName == NULL) {
return WS_MEMORY_E;
}

/* Use attributes and fName to create long name */
if (SFTP_CreateLongName(out) != WS_SUCCESS) {
WLOG(WS_LOG_DEBUG, "Error creating long name for %s", out->fName);
WFREE(out->fName, out->heap, DYNTYPE_SFTP);
return WS_FATAL_ERROR;
}

return WS_SUCCESS;
}

#else

/* helper function that gets file information from reading directory
Expand Down

0 comments on commit f07aa1b

Please sign in to comment.