From b1c748c1371dc37f606392e53ab972832761eee9 Mon Sep 17 00:00:00 2001 From: oliverschmidt Date: Sat, 9 Feb 2008 17:15:58 +0000 Subject: [PATCH] Adjusted telnet server to the new shell logic. --- apps/telnetd/Makefile.telnetd | 4 ++- apps/telnetd/telnetd-gui.c | 16 ++++++------ apps/telnetd/telnetd.c | 49 +++++++++++++++++++++++------------ apps/telnetd/telnetd.h | 4 +-- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/apps/telnetd/Makefile.telnetd b/apps/telnetd/Makefile.telnetd index ec2f6c7b6..33721c49f 100644 --- a/apps/telnetd/Makefile.telnetd +++ b/apps/telnetd/Makefile.telnetd @@ -1,3 +1,5 @@ -telnetd_src = telnetd.c memb.c shell.c +telnetd_src = telnetd.c memb.c \ + shell.c shell-file.c shell-ps.c shell-run.c \ + shell-text.c shell-time.c list.c random.c telnetd_dsc = telnetd-dsc.c APPDIRS += $(CONTIKI)/apps/shell diff --git a/apps/telnetd/telnetd-gui.c b/apps/telnetd/telnetd-gui.c index a4fa3149c..7fdeb7bd8 100644 --- a/apps/telnetd/telnetd-gui.c +++ b/apps/telnetd/telnetd-gui.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki desktop OS. * - * $Id: telnetd-gui.c,v 1.2 2007/04/13 22:02:28 oliverschmidt Exp $ + * $Id: telnetd-gui.c,v 1.3 2008/02/09 17:15:58 oliverschmidt Exp $ * */ @@ -54,20 +54,20 @@ static struct ctk_label loglabel = /*-----------------------------------------------------------------------------------*/ void -telnetd_gui_output(char *str1, char *str2) +telnetd_gui_output(const char *str1, int len1, const char *str2, int len2) { - static unsigned int len, i; + static unsigned int i; for(i = 1; i < YSIZE; ++i) { memcpy(&log[(i - 1) * XSIZE], &log[i * XSIZE], XSIZE); } - memset(&log[(YSIZE - 1) * XSIZE], 0, XSIZE); - - len = (unsigned int)strlen(str1); strncpy(&log[(YSIZE - 1) * XSIZE], str1, XSIZE); - if(len < XSIZE) { - strncpy(&log[(YSIZE - 1) * XSIZE] + len, str2, XSIZE - len); + if(len1 < XSIZE) { + strncpy(&log[(YSIZE - 1) * XSIZE] + len1, str2, XSIZE - len1); + if(len1 + len2 < XSIZE) { + log[(YSIZE - 1) * XSIZE + len1 + len2] = 0; + } } CTK_WIDGET_REDRAW(&loglabel); diff --git a/apps/telnetd/telnetd.c b/apps/telnetd/telnetd.c index cb71655cc..5eb86dc21 100644 --- a/apps/telnetd/telnetd.c +++ b/apps/telnetd/telnetd.c @@ -28,20 +28,19 @@ * * This file is part of the Contiki desktop OS. * - * $Id: telnetd.c,v 1.7 2007/11/17 20:13:54 oliverschmidt Exp $ + * $Id: telnetd.c,v 1.8 2008/02/09 17:15:58 oliverschmidt Exp $ * */ +#include + +#include "contiki-lib.h" #include "contiki-net.h" #include "lib/petsciiconv.h" -#include "contiki-lib.h" - #include "shell.h" + #include "telnetd.h" - -#include - #define ISO_nl 0x0a #define ISO_cr 0x0d @@ -50,6 +49,8 @@ PROCESS(telnetd_process, "Shell server"); +AUTOSTART_PROCESSES(&telnetd_process); + #ifndef TELNETD_CONF_LINELEN #define TELNETD_CONF_LINELEN 40 #endif @@ -58,13 +59,13 @@ PROCESS(telnetd_process, "Shell server"); #endif struct telnetd_line { - char line[TELNETD_CONF_LINELEN]; + char line[TELNETD_CONF_LINELEN + 1]; }; MEMB(linemem, struct telnetd_line, TELNETD_CONF_NUMLINES); struct telnetd_state { char *lines[TELNETD_CONF_NUMLINES]; - char buf[TELNETD_CONF_LINELEN]; + char buf[TELNETD_CONF_LINELEN + 1]; char bufptr; u8_t numsent; u8_t state; @@ -142,20 +143,30 @@ shell_prompt(char *str) } /*-----------------------------------------------------------------------------------*/ void -shell_output(char *str1, char *str2) +shell_default_output(const char *str1, int len1, const char *str2, int len2) { static unsigned len; char *line; + if(str1[len1 - 1] == '\n') { + --len1; + } + if(str2[len2 - 1] == '\n') { + --len2; + } + #if TELNETD_CONF_GUI - telnetd_gui_output(str1, str2); + telnetd_gui_output(str1, len1, str2, len2); #endif /* TELNETD_CONF_GUI */ line = alloc_line(); if(line != NULL) { - len = (unsigned int)strlen(str1); + line[TELNETD_CONF_LINELEN] = 0; strncpy(line, str1, TELNETD_CONF_LINELEN); - if(len < TELNETD_CONF_LINELEN) { - strncpy(line + len, str2, TELNETD_CONF_LINELEN - len); + if(len1 < TELNETD_CONF_LINELEN) { + strncpy(line + len1, str2, TELNETD_CONF_LINELEN - len1); + if(len1 + len2 < TELNETD_CONF_LINELEN) { + line[len1 + len2] = 0; + } } len = (unsigned int)strlen(line); if(len < TELNETD_CONF_LINELEN - 2) { @@ -174,7 +185,14 @@ PROCESS_THREAD(telnetd_process, ev, data) tcp_listen(HTONS(23)); memb_init(&linemem); + shell_init(); + shell_file_init(); + shell_ps_init(); + shell_run_init(); + shell_text_init(); + shell_time_init(); + #if TELNETD_CONF_GUI telnetd_gui_init(); #endif /* TELNETD_CONF_GUI */ @@ -186,7 +204,6 @@ PROCESS_THREAD(telnetd_process, ev, data) } else if(ev == PROCESS_EVENT_EXIT) { telnetd_quit(); } else { - shell_eventhandler(ev, data); #if TELNETD_CONF_GUI telnetd_gui_eventhandler(ev, data); #endif /* TELNETD_CONF_GUI */ @@ -263,7 +280,7 @@ get_char(u8_t c) s.buf[(int)s.bufptr] = 0; petsciiconv_topetscii(s.buf, TELNETD_CONF_LINELEN); } - shell_input(s.buf); + shell_input(s.buf, s.bufptr); s.bufptr = 0; } else { ++s.bufptr; @@ -364,8 +381,6 @@ telnetd_appcall(void *ts) } s.bufptr = 0; s.state = STATE_NORMAL; - - shell_start(); } if(s.state == STATE_CLOSE) { diff --git a/apps/telnetd/telnetd.h b/apps/telnetd/telnetd.h index c6683adc3..c8bbe8eb4 100644 --- a/apps/telnetd/telnetd.h +++ b/apps/telnetd/telnetd.h @@ -29,7 +29,7 @@ * * This file is part of the Contiki desktop environment * - * $Id: telnetd.h,v 1.3 2007/11/30 11:15:41 oliverschmidt Exp $ + * $Id: telnetd.h,v 1.4 2008/02/09 17:15:58 oliverschmidt Exp $ * */ #ifndef __TELNETD_H__ @@ -42,7 +42,7 @@ PROCESS_NAME(telnetd_process); void telnetd_gui_eventhandler(process_event_t ev, process_data_t data); void telnetd_appcall(void *data); void telnetd_gui_init(void); -void telnetd_gui_output(char *str1, char *str2); +void telnetd_gui_output(const char *str1, int len1, const char *str2, int len2); void telnetd_gui_quit(void); void telnetd_quit(void);