diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-06-05 18:53:46 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-06-05 18:53:46 +0000 |
commit | 260b4435a85b9f4ae5d70830c1259af7afee256f (patch) | |
tree | 37aac92ff9a19ef32dc04b0d9d70c24a8233a278 /apps/netutils/ftpc/ftpc_getreply.c | |
parent | 672c0505c6c10c227c9315ed4f94746462392ea5 (diff) | |
download | nuttx-260b4435a85b9f4ae5d70830c1259af7afee256f.tar.gz nuttx-260b4435a85b9f4ae5d70830c1259af7afee256f.tar.bz2 nuttx-260b4435a85b9f4ae5d70830c1259af7afee256f.zip |
More FTP fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3672 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/netutils/ftpc/ftpc_getreply.c')
-rw-r--r-- | apps/netutils/ftpc/ftpc_getreply.c | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/apps/netutils/ftpc/ftpc_getreply.c b/apps/netutils/ftpc/ftpc_getreply.c index 50d392a5f..058eaf213 100644 --- a/apps/netutils/ftpc/ftpc_getreply.c +++ b/apps/netutils/ftpc/ftpc_getreply.c @@ -72,7 +72,7 @@ static int ftpc_gets(struct ftpc_session_s *session) { int ch; - int i = 0; + int ndx = 0; /* Start wth an empty response string */ @@ -93,12 +93,18 @@ static int ftpc_gets(struct ftpc_session_s *session) /* Get the next character from incoming command stream */ ch = ftpc_sockgetc(&session->cmd); + + /* Check if the command stream was closed */ + if (ch == EOF) { ndbg("EOF: Server closed command stream\n"); ftpc_reset(session); return ERROR; } + + /* Handle embedded Telnet stuff */ + else if (ch == TELNET_IAC) { /* Handle TELNET commands */ @@ -125,26 +131,43 @@ static int ftpc_gets(struct ftpc_session_s *session) continue; } + + /* Deal with carriage returns */ + else if (ch == ISO_cr) { + /* What follows the carriage return? */ + ch = ftpc_sockgetc(&session->cmd); if (ch == '\0') { + /* If it is followed by a NUL then keep it */ + ch = ISO_cr; } + + /* If it is followed by a newline then break out of the loop. */ + else if (ch == ISO_nl) { - session->reply[i++] = (char)ch; + /* Newline terminates the reply */ + break; } + + /* If we did not lose the connection, then push the character + * following the carriage back on the "stack" and continue to + * examine it from scratch (if could be part of the Telnet + * protocol). + */ + else if (ch != EOF) { - /* TELNET protocol */ - ungetc(ch, session->cmd.instream); continue; } } + else if (ch == ISO_nl) { /* The ISO newline character terminates the string. Just break @@ -154,21 +177,24 @@ static int ftpc_gets(struct ftpc_session_s *session) break; } - if (i < CONFIG_FTP_MAXREPLY) + /* Put the character into the response buffer. Is there space for + * another character in the reply buffer? + */ + + if (ndx < CONFIG_FTP_MAXREPLY) { - session->reply[i++] = (char)ch; + /* Yes.. put the character in the reply buffer */ + + session->reply[ndx++] = (char)ch; } - - if (i >= CONFIG_FTP_MAXREPLY) + else { ndbg("Reply truncated\n"); - i = CONFIG_FTP_MAXREPLY; } } - session->reply[i] = '\0'; + session->reply[ndx] = '\0'; session->code = atoi(session->reply); - ftpc_stripcrlf(session->reply); return session->code; } @@ -233,7 +259,8 @@ int fptc_getreply(struct ftpc_session_s *session) } nvdbg("Reply: %s\n", session->reply); - } while(strncmp(tmp, session->reply, 4) != 0); + } + while (strncmp(tmp, session->reply, 4) != 0); } wd_cancel(session->wdog); |