You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/12/13 17:14:51 UTC

[incubator-nuttx-apps] branch master updated (db0b595 -> 2a11d60)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.


    from db0b595  Remove unneeded semicolons and parentheses from Python files
     new 8f0e872  netutils/ftpc/ftpc_listdir.c: fix hardfault when issuing 'ls' before 'login'
     new 4a56546  netutils/ftpc: add config for using binary type for size command
     new 810398d  netutils/ftpc: add some error checks
     new 2a11d60  netutils/ftpc: fix incorrect comments, nxstyle

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/netutils/ftpc.h       | 21 ++++++++++----------
 netutils/dhcpd/Makefile       |  2 +-
 netutils/ftpc/Kconfig         |  6 ++++++
 netutils/ftpc/Makefile        |  2 --
 netutils/ftpc/ftpc_cmd.c      | 39 +++++++++++--------------------------
 netutils/ftpc/ftpc_filesize.c | 27 ++++++--------------------
 netutils/ftpc/ftpc_listdir.c  | 45 ++++++++++++++++++++++++++-----------------
 netutils/ftpc/ftpc_login.c    | 25 ++++--------------------
 netutils/ftpc/ftpc_mkdir.c    | 25 +++++-------------------
 netutils/ftpc/ftpc_rename.c   | 35 +++++++++++++--------------------
 netutils/ftpc/ftpc_rmdir.c    | 26 ++++++-------------------
 netutils/ftpc/ftpc_rpwd.c     | 23 ++--------------------
 netutils/ftpc/ftpc_transfer.c | 22 +++++----------------
 netutils/ftpc/ftpc_utils.c    | 23 ++++------------------
 14 files changed, 101 insertions(+), 220 deletions(-)


[incubator-nuttx-apps] 03/04: netutils/ftpc: add some error checks

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 810398de016beb9c790515d7ff6818b1803d951a
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Sun Dec 13 17:35:13 2020 +0200

    netutils/ftpc: add some error checks
    
    Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
 netutils/ftpc/ftpc_login.c    |  5 ++++-
 netutils/ftpc/ftpc_mkdir.c    |  5 +++++
 netutils/ftpc/ftpc_rename.c   | 12 +++++++++++-
 netutils/ftpc/ftpc_rmdir.c    |  5 +++++
 netutils/ftpc/ftpc_transfer.c |  6 +++++-
 5 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/netutils/ftpc/ftpc_login.c b/netutils/ftpc/ftpc_login.c
index 8f21309..6f9f534 100644
--- a/netutils/ftpc/ftpc_login.c
+++ b/netutils/ftpc/ftpc_login.c
@@ -187,7 +187,10 @@ int ftpc_relogin(FAR struct ftpc_session_s *session)
 
   FTPC_SET_LOGGEDIN(session);
   session->homerdir = ftpc_rpwd((SESSION)session);
-  session->currdir  = strdup(session->homerdir);
+  if (session->homerdir != NULL)
+    {
+      session->currdir = strdup(session->homerdir);
+    }
 
   /* If the user has requested a special start up directory, then change to
    * that directory now.
diff --git a/netutils/ftpc/ftpc_mkdir.c b/netutils/ftpc/ftpc_mkdir.c
index 27981b4..bd32121 100644
--- a/netutils/ftpc/ftpc_mkdir.c
+++ b/netutils/ftpc/ftpc_mkdir.c
@@ -85,6 +85,11 @@ int ftpc_mkdir(SESSION handle, FAR const char *path)
   int ret;
 
   ptr = strdup(path);
+  if (!ptr)
+    {
+      return ERROR;
+    }
+
   ftpc_stripslash(ptr);
 
   /* Send the MKD request. The MKD request asks the server to create a new
diff --git a/netutils/ftpc/ftpc_rename.c b/netutils/ftpc/ftpc_rename.c
index ec8aae8..c5d735a 100644
--- a/netutils/ftpc/ftpc_rename.c
+++ b/netutils/ftpc/ftpc_rename.c
@@ -86,6 +86,11 @@ int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname
   int ret;
 
   oldcopy = strdup(oldname);
+  if (!oldcopy)
+    {
+      return ERROR;
+    }
+
   ftpc_stripslash(oldcopy);
 
   /* A RNFR request asks the server to begin renaming a file. A typical
@@ -107,7 +112,13 @@ int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname
       return ERROR;
     }
 
+  free(oldcopy);
   newcopy = strdup(newname);
+  if (!newcopy)
+    {
+      return ERROR;
+    }
+
   ftpc_stripslash(newcopy);
 
   /* A RNTO request asks the server to finish renaming a file. RNTO must
@@ -128,7 +139,6 @@ int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname
 
   ret = ftpc_cmd(session, "RNTO %s", newcopy);
 
-  free(oldcopy);
   free(newcopy);
   return ret;
 }
diff --git a/netutils/ftpc/ftpc_rmdir.c b/netutils/ftpc/ftpc_rmdir.c
index 4cf5cdf..5f78ef2 100644
--- a/netutils/ftpc/ftpc_rmdir.c
+++ b/netutils/ftpc/ftpc_rmdir.c
@@ -83,6 +83,11 @@ int ftpc_rmdir(SESSION handle, FAR const char *path)
   int ret;
 
   ptr = strdup(path);
+  if (!ptr)
+    {
+      return ERROR;
+    }
+
   ftpc_stripslash(ptr);
 
   /* An RMD request asks the server to remove a directory. A typical server
diff --git a/netutils/ftpc/ftpc_transfer.c b/netutils/ftpc/ftpc_transfer.c
index 72cbace..b983a13 100644
--- a/netutils/ftpc/ftpc_transfer.c
+++ b/netutils/ftpc/ftpc_transfer.c
@@ -557,7 +557,11 @@ int ftpc_xfrmode(struct ftpc_session_s *session, uint8_t xfrmode)
 
       ret = ftpc_cmd(session, "TYPE %c",
                      xfrmode == FTPC_XFRMODE_ASCII ? 'A' : 'I');
-      UNUSED(ret);
+      if (ret < 0)
+        {
+          return ERROR;
+        }
+
       session->xfrmode = xfrmode;
     }
 


[incubator-nuttx-apps] 04/04: netutils/ftpc: fix incorrect comments, nxstyle

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 2a11d60246e670261d74381f925f9e59244d560f
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Sun Dec 13 17:35:40 2020 +0200

    netutils/ftpc: fix incorrect comments, nxstyle
    
    Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
 include/netutils/ftpc.h       | 21 +++++++++++----------
 netutils/dhcpd/Makefile       |  2 +-
 netutils/ftpc/Makefile        |  2 --
 netutils/ftpc/ftpc_cmd.c      | 39 +++++++++++----------------------------
 netutils/ftpc/ftpc_listdir.c  | 25 ++++++++-----------------
 netutils/ftpc/ftpc_login.c    | 20 --------------------
 netutils/ftpc/ftpc_mkdir.c    | 20 --------------------
 netutils/ftpc/ftpc_rename.c   | 23 ++---------------------
 netutils/ftpc/ftpc_rmdir.c    | 21 +--------------------
 netutils/ftpc/ftpc_rpwd.c     | 23 ++---------------------
 netutils/ftpc/ftpc_transfer.c | 16 ----------------
 netutils/ftpc/ftpc_utils.c    | 23 ++++-------------------
 12 files changed, 40 insertions(+), 195 deletions(-)

diff --git a/include/netutils/ftpc.h b/include/netutils/ftpc.h
index 64c16a8..5b2dbab 100644
--- a/include/netutils/ftpc.h
+++ b/include/netutils/ftpc.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * apps/include/system/ftpc.h
+ * apps/include/netutils/ftpc.h
  *
  *   Copyright (C) 2011, 2015-2016 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
@@ -53,6 +53,7 @@
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
+
 /* Configuration ************************************************************/
 
 #ifndef CONFIG_FTP_DEFTIMEO
@@ -88,6 +89,7 @@
 #endif
 
 /* Interface arguments ******************************************************/
+
 /* These definitions describe how a put operation should be performed */
 
 #define FTPC_PUT_NORMAL      0  /* Just PUT the file on the server */
@@ -110,18 +112,15 @@
 /****************************************************************************
  * Public Types
  ****************************************************************************/
+
 /* This "handle" describes the FTP session */
 
 typedef FAR void *SESSION;
 
-/* This union provides information to connect to a host FTP server.
+/* This union provides socket address to connect to a host FTP server.
  *
- * addr - The IPv4 or IPv6 address of the FTP server (or the proxy) for the FTP
- *        server.
- * port - The port number on the FTP server to connect to (in host byte
- *        order).  This is usually port 21 for FTP.  You may set this
- *        value to zero to let FTPC select the default port number for
- *        you (it will use CONFIG_FTP_DEFPORT).
+ * in4, in6 - The IPv4 or IPv6 address of the FTP server (or the proxy)
+ *            for the FTP server.
  */
 
 union ftpc_sockaddr_u
@@ -181,8 +180,9 @@ extern "C"
 #endif
 
 /****************************************************************************
- * Public Functions
+ * Public Function Prototypes
  ****************************************************************************/
+
 /* Connection management ****************************************************/
 
 SESSION ftpc_connect(FAR union ftpc_sockaddr_u *server);
@@ -201,7 +201,8 @@ int ftpc_rmdir(SESSION handle, FAR const char *path);
 
 int ftpc_unlink(SESSION handle, FAR const char *path);
 int ftpc_chmod(SESSION handle, FAR const char *path, FAR const char *mode);
-int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname);
+int ftpc_rename(SESSION handle, FAR const char *oldname,
+                FAR const char *newname);
 off_t ftpc_filesize(SESSION handle, FAR const char *path);
 time_t ftpc_filetime(SESSION handle, FAR const char *filename);
 
diff --git a/netutils/dhcpd/Makefile b/netutils/dhcpd/Makefile
index b393b32..515b774 100644
--- a/netutils/dhcpd/Makefile
+++ b/netutils/dhcpd/Makefile
@@ -35,7 +35,7 @@
 
 include $(APPDIR)/Make.defs
 
-# DHCP Daemn Library
+# DHCP Daemon Library
 
 ifeq ($(CONFIG_NET_UDP),y)
 CSRCS = dhcpd.c
diff --git a/netutils/ftpc/Makefile b/netutils/ftpc/Makefile
index 2396a35..bfa2ced 100644
--- a/netutils/ftpc/Makefile
+++ b/netutils/ftpc/Makefile
@@ -35,8 +35,6 @@
 
 include $(APPDIR)/Make.defs
 
-# DHCP Daemn Library
-
 ifeq ($(CONFIG_NET_TCP),y)
 # FTP connection management
 CSRCS += ftpc_connect.c ftpc_disconnect.c
diff --git a/netutils/ftpc/ftpc_cmd.c b/netutils/ftpc/ftpc_cmd.c
index d12a24b..ec85e5c 100644
--- a/netutils/ftpc/ftpc_cmd.c
+++ b/netutils/ftpc/ftpc_cmd.c
@@ -48,26 +48,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
@@ -106,8 +86,9 @@ static int ftpc_restore(struct ftpc_session_s *session)
 
           ftpc_reset(session);
         }
+
       return ret;
-  }
+    }
 
   return ERROR;
 }
@@ -136,15 +117,15 @@ int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...)
   /* Verify that we are still connected to the server */
 
   if (!ftpc_sockconnected(&session->cmd))
-  {
-    nwarn("WARNING: Cmd channel is not connected\n");
-    goto errout;
-  }
+    {
+      nwarn("WARNING: Cmd channel is not connected\n");
+      goto errout;
+    }
 
   /* Loop, reconnecting as necessary until the command is sent */
 
 #ifdef CONFIG_FTP_AUTORECONNECT
-  for (;;)
+  for (; ; )
 #endif
     {
       /* Send the command */
@@ -159,6 +140,7 @@ int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...)
               ret = ftpc_sockflush(&session->cmd);
             }
         }
+
       va_end(ap);
 
       /* Check for an error in sending the data */
@@ -167,7 +149,7 @@ int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...)
         {
           nerr("ERROR: Error sending cmd %s: %d\n", cmd, errno);
           goto errout;
-       }
+        }
 
       /* Get the response to the command */
 
@@ -176,7 +158,7 @@ int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...)
         {
           nerr("ERROR: Error getting reply: %d\n", errno);
           goto errout;
-       }
+        }
 
       /* Check for "421 Service not available, closing control connection" */
 
@@ -214,6 +196,7 @@ int ftpc_cmd(struct ftpc_session_s *session, const char *cmd, ...)
                       nwarn("WARNING: Failed to restore the connection");
                       goto errout;
                     }
+
                   continue;
                 }
             }
diff --git a/netutils/ftpc/ftpc_listdir.c b/netutils/ftpc/ftpc_listdir.c
index 60ff370..213ed22 100644
--- a/netutils/ftpc/ftpc_listdir.c
+++ b/netutils/ftpc/ftpc_listdir.c
@@ -52,24 +52,12 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
  * Private Types
  ****************************************************************************/
 
 typedef void (*callback_t)(FAR const char *name, FAR void *arg);
 
 /****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
@@ -111,8 +99,9 @@ static void ftpc_addname(FAR const char *name, FAR void *arg)
  *   sequence of pathnames. Each pathname is terminated by \r\n.
  *
  *   If a pathname starts with a slash, it represents the pathname. If a
- *   pathname does not start with a slash, it represents the pathname obtained
- *   by concatenating the pathname of the directory and the pathname.
+ *   pathname does not start with a slash, it represents the pathname
+ *   obtained by concatenating the pathname of the directory and the
+ *   pathname.
  *
  *   IF NLST of directory /pub produces foo\r\nbar\r\n, it refers to the
  *   pathnames /pub/foo and /pub/bar.
@@ -122,11 +111,11 @@ static void ftpc_addname(FAR const char *name, FAR void *arg)
 static void ftpc_nlstparse(FAR FILE *instream, callback_t callback,
                            FAR void *arg)
 {
-  char buffer[CONFIG_FTP_MAXPATH+1];
+  char buffer[CONFIG_FTP_MAXPATH + 1];
 
   /* Read every filename from the temporary file */
 
-  for (;;)
+  for (; ; )
     {
       /* Read the next line from the file */
 
@@ -145,6 +134,7 @@ static void ftpc_nlstparse(FAR FILE *instream, callback_t callback,
         {
           break;
         }
+
       ninfo("File: %s\n", buffer);
 
       /* Perform the callback operation */
@@ -265,7 +255,7 @@ static int ftpc_recvdir(FAR struct ftpc_session_s *session,
  *   expansion "~/xyz" and relative paths (abc/def) because we do have
  *   special knowledge about the home and current directories.  But otherwise
  *   the paths are expected to be pre-sanitized:  No . or .. in paths,
- *   no '//' in paths, etc.
+ *   no multiple consecutive '/' in paths, etc.
  *
  ****************************************************************************/
 
@@ -367,6 +357,7 @@ FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle,
           nwarn("WARNING: Nothing found in directory\n");
           goto errout;
         }
+
       ninfo("nnames: %d\n", nnames);
 
       /* Allocate and initialize a directory container */
diff --git a/netutils/ftpc/ftpc_login.c b/netutils/ftpc/ftpc_login.c
index 6f9f534..7691ae4 100644
--- a/netutils/ftpc/ftpc_login.c
+++ b/netutils/ftpc/ftpc_login.c
@@ -33,26 +33,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
diff --git a/netutils/ftpc/ftpc_mkdir.c b/netutils/ftpc/ftpc_mkdir.c
index bd32121..15e93d3 100644
--- a/netutils/ftpc/ftpc_mkdir.c
+++ b/netutils/ftpc/ftpc_mkdir.c
@@ -47,26 +47,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
diff --git a/netutils/ftpc/ftpc_rename.c b/netutils/ftpc/ftpc_rename.c
index c5d735a..3b67671 100644
--- a/netutils/ftpc/ftpc_rename.c
+++ b/netutils/ftpc/ftpc_rename.c
@@ -47,26 +47,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -78,7 +58,8 @@
  *
  ****************************************************************************/
 
-int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname)
+int ftpc_rename(SESSION handle, FAR const char *oldname,
+                FAR const char *newname)
 {
   FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)handle;
   char *oldcopy;
diff --git a/netutils/ftpc/ftpc_rmdir.c b/netutils/ftpc/ftpc_rmdir.c
index 5f78ef2..d9ddbed 100644
--- a/netutils/ftpc/ftpc_rmdir.c
+++ b/netutils/ftpc/ftpc_rmdir.c
@@ -46,26 +46,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -76,6 +56,7 @@
  *   Deletes the named directory on the remote server.
  *
  ****************************************************************************/
+
 int ftpc_rmdir(SESSION handle, FAR const char *path)
 {
   FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)handle;
diff --git a/netutils/ftpc/ftpc_rpwd.c b/netutils/ftpc/ftpc_rpwd.c
index 5c8e49e..db4d210 100644
--- a/netutils/ftpc/ftpc_rpwd.c
+++ b/netutils/ftpc/ftpc_rpwd.c
@@ -48,26 +48,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -103,6 +83,7 @@ FAR char *ftpc_rpwd(SESSION handle)
       nwarn("WARNING: Opening quote not found\n");
       return NULL;
     }
+
   start++;
 
   end = strchr(start, '\"');
@@ -133,7 +114,7 @@ FAR char *ftpc_rpwd(SESSION handle)
   memcpy(pwd, start, len);
   pwd[len] = '\0';
 
-  /* Remove any trailing slashes that the server may have added */
+  /* Remove any trailing slash that the server may have added */
 
   ftpc_stripslash(pwd);
 
diff --git a/netutils/ftpc/ftpc_transfer.c b/netutils/ftpc/ftpc_transfer.c
index b983a13..47f0d2e 100644
--- a/netutils/ftpc/ftpc_transfer.c
+++ b/netutils/ftpc/ftpc_transfer.c
@@ -57,22 +57,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
diff --git a/netutils/ftpc/ftpc_utils.c b/netutils/ftpc/ftpc_utils.c
index 90793d1..8dca41a 100644
--- a/netutils/ftpc/ftpc_utils.c
+++ b/netutils/ftpc/ftpc_utils.c
@@ -45,22 +45,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
@@ -139,6 +123,7 @@ FAR const char *ftpc_lpwd(void)
     {
       val = CONFIG_FTP_TMPDIR;
     }
+
   return val;
 #else
   return CONFIG_FTP_TMPDIR;
@@ -178,8 +163,8 @@ void ftpc_stripcrlf(FAR char *str)
  * Name: ftpc_stripslash
  *
  * Description:
- *   Strip any trailing slashes from a string (by overwriting them with NUL
- *   characters.
+ *   Strip single trailing slash from a string (by overwriting it with NUL
+ *   character).
  *
  ****************************************************************************/
 
@@ -223,7 +208,7 @@ FAR char *ftpc_dequote(FAR const char *str)
       /* Allocate space for a modifiable copy of the string */
 
       len      = strlen(str);
-      allocstr = (FAR char*)malloc(len + 1);
+      allocstr = (FAR char *)malloc(len + 1);
       if (allocstr)
         {
           /* Search the string */


[incubator-nuttx-apps] 02/04: netutils/ftpc: add config for using binary type for size command

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 4a56546811eac830d998815e8f005aa7720fff5d
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Sun Dec 13 17:27:39 2020 +0200

    netutils/ftpc: add config for using binary type for size command
    
    This is handy for FOTA clients and others that always get binary files.
    
    Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
 netutils/ftpc/Kconfig         |  6 ++++++
 netutils/ftpc/ftpc_filesize.c | 27 ++++++---------------------
 2 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/netutils/ftpc/Kconfig b/netutils/ftpc/Kconfig
index ff3f031..9df8694 100644
--- a/netutils/ftpc/Kconfig
+++ b/netutils/ftpc/Kconfig
@@ -26,6 +26,12 @@ config FTP_TMPDIR
 		The path to use for storing temporary files used in the transfer process
 		by the FTP client.
 
+config FTP_SIZE_CMD_MODE_BINARY
+	bool "Use binary mode for size command"
+	default n
+	---help---
+		Use binary transfer mode for FTP size command.
+
 config FTPC_DISABLE_EPRT
 	bool "Disable EPRT and use PORT instead"
 	default n
diff --git a/netutils/ftpc/ftpc_filesize.c b/netutils/ftpc/ftpc_filesize.c
index 4e886f5..efd3419 100644
--- a/netutils/ftpc/ftpc_filesize.c
+++ b/netutils/ftpc/ftpc_filesize.c
@@ -47,26 +47,6 @@
 #include "ftpc_internal.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -82,6 +62,7 @@ off_t ftpc_filesize(SESSION handle, FAR const char *path)
 {
   FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)handle;
   unsigned long ret;
+  uint8_t mode = FTPC_XFRMODE_ASCII;
 
   /* Check if the host supports the SIZE command */
 
@@ -90,7 +71,11 @@ off_t ftpc_filesize(SESSION handle, FAR const char *path)
       return ERROR;
     }
 
-  if (ftpc_xfrmode(session, FTPC_XFRMODE_ASCII) != 0)
+#ifdef CONFIG_FTP_SIZE_CMD_MODE_BINARY
+  mode = FTPC_XFRMODE_BINARY;
+#endif
+
+  if (ftpc_xfrmode(session, mode) != 0)
     {
       return ERROR;
     }


[incubator-nuttx-apps] 01/04: netutils/ftpc/ftpc_listdir.c: fix hardfault when issuing 'ls' before 'login'

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 8f0e87238427662e6d6c07cd5b1f40bedc62106b
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Sun Dec 13 17:26:10 2020 +0200

    netutils/ftpc/ftpc_listdir.c: fix hardfault when issuing 'ls' before 'login'
    
    Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
 netutils/ftpc/ftpc_listdir.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/netutils/ftpc/ftpc_listdir.c b/netutils/ftpc/ftpc_listdir.c
index cf77853..60ff370 100644
--- a/netutils/ftpc/ftpc_listdir.c
+++ b/netutils/ftpc/ftpc_listdir.c
@@ -282,9 +282,21 @@ FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle,
   int allocsize;
   int ret;
 
+  /* If no remote current directory, we are not logged in. */
+
+  if (!session->currdir)
+    {
+      return NULL;
+    }
+
   /* Get the absolute path to the directory */
 
   absrpath = ftpc_absrpath(session, dirpath);
+  if (!absrpath)
+    {
+      return NULL;
+    }
+
   ftpc_stripslash(absrpath);
 
   /* Is the directory also the remote current working directory? */
@@ -293,7 +305,13 @@ FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle,
 
   /* Create a temporary file to hold the directory listing */
 
-  asprintf(&tmpfname, "%s/TMP%d.dat", CONFIG_FTP_TMPDIR, getpid());
+  ret = asprintf(&tmpfname, "%s/TMP%d.dat", CONFIG_FTP_TMPDIR, getpid());
+  if (ret < 0)
+    {
+      free(absrpath);
+      return NULL;
+    }
+
   filestream = fopen(tmpfname, "w+");
   if (!filestream)
     {