From bd6bf35ffd5139fd37e3933c4363a607dbe72373 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Wed, 10 Jan 2018 07:15:16 +0900 Subject: [PATCH] nshlib/nsh_telnetd.c: Add support for telnet character mode. Signed-off-by: Masayuki Ishikawa --- nshlib/nsh_telnetd.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c index ae65dda89..98c78f2ba 100644 --- a/nshlib/nsh_telnetd.c +++ b/nshlib/nsh_telnetd.c @@ -48,6 +48,14 @@ #include "netutils/telnetd.h" +#ifdef CONFIG_TELNET_CHARACTER_MODE +#ifdef CONFIG_NSH_CLE +# include "system/cle.h" +#else +# include "system/readline.h" +#endif +#endif + #include "nsh.h" #include "nsh_console.h" @@ -76,6 +84,7 @@ static int nsh_telnetmain(int argc, char *argv[]) { FAR struct console_stdio_s *pstate = nsh_newconsole(); FAR struct nsh_vtbl_s *vtbl; + int ret; DEBUGASSERT(pstate != NULL); vtbl = &pstate->cn_vtbl; @@ -142,8 +151,27 @@ static int nsh_telnetmain(int argc, char *argv[]) fflush(pstate->cn_outstream); /* Get the next line of input from the Telnet client */ +#ifdef CONFIG_TELNET_CHARACTER_MODE +#ifdef CONFIG_NSH_CLE + ret = cle(pstate->cn_line, CONFIG_NSH_LINELEN, + INSTREAM(pstate), OUTSTREAM(pstate)); +#else + ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN, + INSTREAM(pstate), OUTSTREAM(pstate)); +#endif +#else + if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, + INSTREAM(pstate)) != NULL) + { + ret = strlen(pstate->cn_line); + } + else + { + ret = EOF; + } +#endif - if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, INSTREAM(pstate)) != NULL) + if (ret != EOF) { /* Parse process the received Telnet command */ @@ -153,7 +181,7 @@ static int nsh_telnetmain(int argc, char *argv[]) else { fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain", - "fgets", NSH_ERRNO); + "cle/readline/fgets", NSH_ERRNO); nsh_exit(vtbl, 1); } }