nshlib: Reuse nsh_session logic in nsh_telnetmain

to avoid the code duplication

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2022-10-17 05:17:41 +08:00
committed by Alan Carvalho de Assis
parent 8e460e7e19
commit 75455d3788
8 changed files with 55 additions and 128 deletions

View File

@@ -66,7 +66,7 @@
****************************************************************************/
int nsh_session(FAR struct console_stdio_s *pstate,
bool login, int argc, FAR char *argv[])
int login, int argc, FAR char *argv[])
{
FAR struct nsh_vtbl_s *vtbl;
int ret = EXIT_FAILURE;
@@ -74,9 +74,9 @@ int nsh_session(FAR struct console_stdio_s *pstate,
DEBUGASSERT(pstate);
vtbl = &pstate->cn_vtbl;
if (login)
{
#ifdef CONFIG_NSH_CONSOLE_LOGIN
if (login == NSH_LOGIN_LOCAL)
{
/* Login User and Password Check */
if (nsh_login(pstate) != OK)
@@ -84,8 +84,24 @@ int nsh_session(FAR struct console_stdio_s *pstate,
nsh_exit(vtbl, 1);
return -1; /* nsh_exit does not return */
}
}
else
#endif /* CONFIG_NSH_CONSOLE_LOGIN */
#ifdef CONFIG_NSH_TELNET_LOGIN
if (login == NSH_LOGIN_TELNET)
{
/* Login User and Password Check */
if (nsh_telnetlogin(pstate) != OK)
{
nsh_exit(vtbl, 1);
return -1; /* nsh_exit does not return */
}
}
#endif /* CONFIG_NSH_TELNET_LOGIN */
if (login != NSH_LOGIN_NONE)
{
/* Present a greeting and possibly a Message of the Day (MOTD) */
fputs(g_nshgreeting, pstate->cn_outstream);