Fix FTP bug -- losing passive mode indication
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3667 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
4287df5472
commit
199695630e
@ -83,23 +83,10 @@ typedef int (*cmd_t)(SESSION handle, int argc, char **argv);
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
extern const char g_ftpcgreeting[];
|
||||
extern const char g_ftpcprompt[];
|
||||
extern const char g_fmtcmdfailed[];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Network initialization */
|
||||
|
||||
extern int ftpc_netinit(void);
|
||||
|
||||
/* Current working directory support */
|
||||
|
||||
extern char *ftpc_getfullpath(const char *relpath);
|
||||
extern void ftpc_freefullpath(char *relpath);
|
||||
|
||||
/* FTP command handlers */
|
||||
|
||||
extern int cmd_rlogin(SESSION handle, int argc, char **argv);
|
||||
|
@ -66,7 +66,7 @@
|
||||
|
||||
int cmd_rlogin(SESSION handle, int argc, char **argv)
|
||||
{
|
||||
struct ftpc_login_s login = {0, 0, 0, true};
|
||||
struct ftpc_login_s login = {NULL, NULL, NULL, true};
|
||||
|
||||
login.uname = argv[1];
|
||||
if (argc > 2)
|
||||
|
@ -99,7 +99,8 @@ SESSION ftpc_connect(FAR struct ftpc_connect_s *server)
|
||||
/* Initialize the session structure with all non-zero and variable values */
|
||||
|
||||
session->addr.s_addr = server->addr.s_addr;
|
||||
session->flags = FTPC_FLAGS_INIT;
|
||||
session->flags &= ~FTPC_FLAGS_CLEAR;
|
||||
session->flags |= FTPC_FLAGS_SET;
|
||||
session->replytimeo = CONFIG_FTP_DEFTIMEO * CLOCKS_PER_SEC;
|
||||
session->conntimeo = CONFIG_FTP_DEFTIMEO * CLOCKS_PER_SEC;
|
||||
session->pid = getpid();
|
||||
|
@ -154,7 +154,7 @@ static int ftpc_recvinit(struct ftpc_session_s *session, FAR const char *path,
|
||||
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
|
||||
if (ret != OK)
|
||||
{
|
||||
ndbg("data connection not accepted\n");
|
||||
ndbg("Data connection not accepted\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -73,24 +73,31 @@
|
||||
|
||||
/* Session flag bits ********************************************************/
|
||||
|
||||
#define FTPC_FLAG_CONNECTED (1 << 0) /* Connected to host */
|
||||
#define FTPC_FLAG_LOGGEDIN (1 << 1) /* Logged in to host */
|
||||
#define FTPC_STATE_FLAGS (0x0003) /* State of connection */
|
||||
#define FTPC_FLAG_PASSIVE (1 << 0) /* Passive mode requested */
|
||||
#define FTPC_SESSION_FLAGS (0x0001) /* Persist throughout the session */
|
||||
|
||||
#define FTPC_FLAG_MDTM (1 << 2) /* Host supports MDTM command */
|
||||
#define FTPC_FLAG_SIZE (1 << 3) /* Host supports SIZE command */
|
||||
#define FTPC_FLAG_PASV (1 << 4) /* Host supports PASV command */
|
||||
#define FTPC_FLAG_STOU (1 << 5) /* Host supports STOU command */
|
||||
#define FTPC_FLAG_CHMOD (1 << 6) /* Host supports SITE CHMOD command */
|
||||
#define FTPC_FLAG_IDLE (1 << 7) /* Host supports SITE IDLE command */
|
||||
#define FTPC_HOSTCAP_FLAGS (0x00fc) /* Host capabilities */
|
||||
#define FTPC_FLAG_CONNECTED (1 << 1) /* Connected to host */
|
||||
#define FTPC_FLAG_LOGGEDIN (1 << 2) /* Logged in to host */
|
||||
#define FTPC_STATE_FLAGS (0x0006) /* State of connection */
|
||||
|
||||
#define FTPC_FLAG_INTERRUPT (1 << 8) /* Transfer interrupted */
|
||||
#define FTPC_FLAG_PUT (1 << 9) /* Transfer is a PUT operation (upload) */
|
||||
#define FTPC_FLAG_PASSIVE (1 << 10) /* Passive mode requested */
|
||||
#define FTPC_XFER_FLAGS (0x0700) /* Transfer related */
|
||||
#define FTPC_FLAG_MDTM (1 << 3) /* Host supports MDTM command */
|
||||
#define FTPC_FLAG_SIZE (1 << 4) /* Host supports SIZE command */
|
||||
#define FTPC_FLAG_PASV (1 << 5) /* Host supports PASV command */
|
||||
#define FTPC_FLAG_STOU (1 << 6) /* Host supports STOU command */
|
||||
#define FTPC_FLAG_CHMOD (1 << 7) /* Host supports SITE CHMOD command */
|
||||
#define FTPC_FLAG_IDLE (1 << 8) /* Host supports SITE IDLE command */
|
||||
#define FTPC_HOSTCAP_FLAGS (0x01f8) /* Host capabilities */
|
||||
|
||||
#define FTPC_FLAGS_INIT FTPC_HOSTCAP_FLAGS
|
||||
#define FTPC_FLAG_INTERRUPT (1 << 9) /* Transfer interrupted */
|
||||
#define FTPC_FLAG_PUT (1 << 10) /* Transfer is a PUT operation (upload) */
|
||||
#define FTPC_XFER_FLAGS (0x0600) /* Transfer related */
|
||||
|
||||
/* These are the bits to be set/cleared when the flags are reset */
|
||||
|
||||
#define FTPC_FLAGS_CLEAR (FTPC_STATE_FLAGS | FTPC_XFER_FLAGS)
|
||||
#define FTPC_FLAGS_SET FTPC_HOSTCAP_FLAGS
|
||||
|
||||
/* Macros to set bits */
|
||||
|
||||
#define FTPC_SET_CONNECTED(s) do { (s)->flags |= FTPC_FLAG_CONNECTED; } while (0)
|
||||
#define FTPC_SET_LOGGEDIN(s) do { (s)->flags |= FTPC_FLAG_LOGGEDIN; } while (0)
|
||||
@ -104,6 +111,8 @@
|
||||
#define FTPC_SET_PUT(s) do { (s)->flags |= FTPC_FLAG_PUT; } while (0)
|
||||
#define FTPC_SET_PASSIVE(s) do { (s)->flags |= FTPC_FLAG_PASSIVE; } while (0)
|
||||
|
||||
/* Macros to clear bits */
|
||||
|
||||
#define FTPC_CLR_CONNECTED(s) do { (s)->flags &= ~FTPC_FLAG_CONNECTED; } while (0)
|
||||
#define FTPC_CLR_LOGGEDIN(s) do { (s)->flags &= ~FTPC_FLAG_LOGGEDIN; } while (0)
|
||||
#define FTPC_CLR_MDTM(s) do { (s)->flags &= ~FTPC_FLAG_MDTM; } while (0)
|
||||
@ -116,6 +125,8 @@
|
||||
#define FTPC_CLR_PUT(s) do { (s)->flags &= ~FTPC_FLAG_PUT; } while (0)
|
||||
#define FTPC_CLR_PASSIVE(s) do { (s)->flags &= ~FTPC_FLAG_PASSIVE; } while (0)
|
||||
|
||||
/* Macros to test bits */
|
||||
|
||||
#define FTPC_IS_CONNECTED(s) (((s)->flags & FTPC_FLAG_CONNECTED) != 0)
|
||||
#define FTPC_IS_LOGGEDIN(s) (((s)->flags & FTPC_FLAG_LOGGEDIN) != 0)
|
||||
#define FTPC_HAS_MDTM(s) (((s)->flags & FTPC_FLAG_MDTM) != 0)
|
||||
|
@ -114,6 +114,7 @@ int ftpc_login(SESSION handle, FAR struct ftpc_login_s *login)
|
||||
FTPC_CLR_PASSIVE(session);
|
||||
if (login->pasv)
|
||||
{
|
||||
nvdbg("Setting passive mode\n");
|
||||
FTPC_SET_PASSIVE(session);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,8 @@ void ftpc_reset(struct ftpc_session_s *session)
|
||||
session->pwd = NULL;
|
||||
free(session->initrdir);
|
||||
session->initrdir = NULL;
|
||||
session->flags = FTPC_FLAGS_INIT;
|
||||
session->flags &= ~FTPC_FLAGS_CLEAR;
|
||||
session->flags |= FTPC_FLAGS_SET;
|
||||
session->xfrmode = FTPC_XFRMODE_UNKNOWN;
|
||||
session->code = 0;
|
||||
session->replytimeo = CONFIG_FTP_DEFTIMEO * CLOCKS_PER_SEC;
|
||||
|
Loading…
Reference in New Issue
Block a user