netutils/ftpd, examples/ftpd: code cleanup and nxstyle
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
parent
31f52a1971
commit
eceaeb926a
@ -36,7 +36,7 @@
|
|||||||
#define __APPS_EXAMPLES_FTPD_FTPD_H
|
#define __APPS_EXAMPLES_FTPD_FTPD_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
@ -48,7 +48,9 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Configuration ************************************************************/
|
/* Configuration ************************************************************/
|
||||||
|
|
||||||
/* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon.
|
/* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon.
|
||||||
* Default: SCHED_PRIORITY_DEFAULT
|
* Default: SCHED_PRIORITY_DEFAULT
|
||||||
* CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the
|
* CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/telnetd/shell.c
|
* examples/ftpd/ftpd_main.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -90,6 +90,7 @@ struct ftpd_globals_s g_ftpdglob;
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: fptd_netinit
|
* Name: fptd_netinit
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -102,7 +103,7 @@ static void fptd_netinit(void)
|
|||||||
uint8_t mac[IFHWADDRLEN];
|
uint8_t mac[IFHWADDRLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Many embedded network interfaces must have a software assigned MAC */
|
/* Many embedded network interfaces must have a software assigned MAC */
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_FTPD_NOMAC
|
#ifdef CONFIG_EXAMPLES_FTPD_NOMAC
|
||||||
mac[0] = 0x00;
|
mac[0] = 0x00;
|
||||||
@ -152,8 +153,8 @@ static void ftpd_accounts(FTPD_SESSION handle)
|
|||||||
{
|
{
|
||||||
account = &g_ftpdaccounts[i];
|
account = &g_ftpdaccounts[i];
|
||||||
|
|
||||||
printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i+1,
|
printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i + 1,
|
||||||
(account->flags & FTPD_ACCOUNTFLAG_SYSTEM) != 0 ? "Root" : "User",
|
(account->flags & FTPD_ACCOUNTFLAG_SYSTEM) ? "Root" : "User",
|
||||||
(!account->user) ? "(none)" : account->user,
|
(!account->user) ? "(none)" : account->user,
|
||||||
(!account->password) ? "(none)" : account->password,
|
(!account->password) ? "(none)" : account->password,
|
||||||
(!account->home) ? "(none)" : account->home);
|
(!account->home) ? "(none)" : account->home);
|
||||||
@ -214,7 +215,8 @@ int ftpd_daemon(int s_argc, char **s_argv)
|
|||||||
|
|
||||||
if (ret != -ETIMEDOUT)
|
if (ret != -ETIMEDOUT)
|
||||||
{
|
{
|
||||||
printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret);
|
printf("FTP daemon [%d] ftpd_session returned %d\n",
|
||||||
|
g_ftpdglob.pid, ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,6 +234,7 @@ int ftpd_daemon(int s_argc, char **s_argv)
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ftpd_main
|
* Name: ftpd_main
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -242,7 +245,6 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
if (!g_ftpdglob.initialized)
|
if (!g_ftpdglob.initialized)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Bring up the network */
|
/* Bring up the network */
|
||||||
|
|
||||||
printf("Initializing the network\n");
|
printf("Initializing the network\n");
|
||||||
@ -263,6 +265,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid);
|
printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_ftpdglob.running)
|
if (!g_ftpdglob.running)
|
||||||
{
|
{
|
||||||
printf("Starting the FTP daemon\n");
|
printf("Starting the FTP daemon\n");
|
||||||
@ -275,7 +278,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("FTP daemon [%d] is running\n", g_ftpdglob.pid);
|
printf("FTP daemon [%d] is running\n", g_ftpdglob.pid);
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
|
|
||||||
include $(APPDIR)/Make.defs
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
# Telnet daemon
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NET_TCP),y)
|
ifeq ($(CONFIG_NET_TCP),y)
|
||||||
CSRCS = ftpd.c
|
CSRCS = ftpd.c
|
||||||
endif
|
endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/n etutils/ftpd.c
|
* apps/netutils/ftpd.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012, 2015, 2020 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2015, 2020 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -1136,9 +1136,9 @@ static FAR struct ftpd_server_s *ftpd_openserver(int port,
|
|||||||
|
|
||||||
/* Initialize the server instance */
|
/* Initialize the server instance */
|
||||||
|
|
||||||
server->sd = -1;
|
server->sd = -1;
|
||||||
server->head = NULL;
|
server->head = NULL;
|
||||||
server->tail = NULL;
|
server->tail = NULL;
|
||||||
|
|
||||||
/* Create the server listen socket */
|
/* Create the server listen socket */
|
||||||
|
|
||||||
@ -1910,9 +1910,7 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype)
|
|||||||
|
|
||||||
if (cmdtype == 0)
|
if (cmdtype == 0)
|
||||||
{
|
{
|
||||||
/* Read from the file.
|
/* Read from the file. */
|
||||||
* Read returns the error condition via errno.
|
|
||||||
*/
|
|
||||||
|
|
||||||
rdbytes = read(session->fd, session->data.buffer, wantsize);
|
rdbytes = read(session->fd, session->data.buffer, wantsize);
|
||||||
if (rdbytes < 0)
|
if (rdbytes < 0)
|
||||||
@ -2384,7 +2382,7 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path,
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
{
|
{
|
||||||
int errval = errno;
|
int errval = errno;
|
||||||
nerr("ERROR: dir() failed: %d\n", errval);
|
nerr("ERROR: opendir() failed: %d\n", errval);
|
||||||
return -errval;
|
return -errval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3557,10 +3555,10 @@ static int ftpd_command_size(FAR struct ftpd_session_s *session)
|
|||||||
}
|
}
|
||||||
else if (!S_ISREG(st.st_mode))
|
else if (!S_ISREG(st.st_mode))
|
||||||
{
|
{
|
||||||
ret = ftpd_response(session->cmd.sd, session->txtimeout,
|
|
||||||
g_respfmt2, 550, ' ', session->param,
|
|
||||||
": not a regular file.");
|
|
||||||
ret = -EPERM;
|
ret = -EPERM;
|
||||||
|
ftpd_response(session->cmd.sd, session->txtimeout,
|
||||||
|
g_respfmt2, 550, ' ', session->param,
|
||||||
|
": not a regular file.");
|
||||||
goto errout_with_abspath;
|
goto errout_with_abspath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3673,9 +3671,9 @@ static int ftpd_command_rnto(FAR struct ftpd_session_s *session)
|
|||||||
|
|
||||||
if (!session->renamefrom)
|
if (!session->renamefrom)
|
||||||
{
|
{
|
||||||
return ftpd_response(session->cmd.sd, session->txtimeout,
|
ftpd_response(session->cmd.sd, session->txtimeout,
|
||||||
g_respfmt1, 550, ' ', "RNTO error !");
|
g_respfmt1, 550, ' ', "RNTO error !");
|
||||||
return ret;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ftpd_getpath(session, session->param, &abspath, NULL);
|
ret = ftpd_getpath(session, session->param, &abspath, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user