netutils/ftpc: Change watchdog callback prototype

follow up the kernel side change

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-08-11 00:54:08 +08:00 committed by patacongo
parent fcd3937d7c
commit efeb1d10b1
4 changed files with 78 additions and 66 deletions

View File

@ -149,7 +149,7 @@ int ftpc_reconnect(FAR struct ftpc_session_s *session)
/* Set up a timer to prevent hangs */
ret = wd_start(&session->wdog, session->conntimeo,
ftpc_timeout, 1, (wdparm_t)session);
ftpc_timeout, (wdparm_t)session);
if (ret != OK)
{
nerr("ERROR: wd_start() failed\n");

View File

@ -218,7 +218,7 @@ int fptc_getreply(struct ftpc_session_s *session)
if (session->replytimeo)
{
ret = wd_start(&session->wdog, session->replytimeo,
ftpc_timeout, 1, (wdparm_t)session);
ftpc_timeout, (wdparm_t)session);
}
/* Get the next line from the server */

View File

@ -268,7 +268,7 @@ EXTERN void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
EXTERN int ftpc_sockprintf(FAR struct ftpc_socket_s *sock,
const char *fmt, ...);
EXTERN void ftpc_timeout(int argc, wdparm_t arg1, ...);
EXTERN void ftpc_timeout(wdparm_t arg);
/* Transfer helpers */

View File

@ -82,21 +82,21 @@
* Description:
* Enter passive mode using EPSV command.
*
* In active mode FTP the client connects from a random port (N>1023) to the
* FTP server's command port, port 21. Then, the client starts listening to
* port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
* will then connect back to the client's specified data port from its local
* data port, which is port 20. In passive mode FTP the client initiates
* both connections to the server, solving the problem of firewalls filtering
* the incoming data port connection to the client from the server. When
* opening an FTP connection, the client opens two random ports locally
* (N>1023 and N+1). The first port contacts the server on port 21, but
* instead of then issuing a PORT command and allowing the server to connect
* back to its data port, the client will issue the PASV command. The result
* of this is that the server then opens a random unprivileged port (P >
* 1023) and sends the PORT P command back to the client. The client then
* initiates the connection from port N+1 to port P on the server to transfer
* data.
* In active mode FTP the client connects from a random port (N>1023) to
* the FTP server's command port, port 21. Then the client starts listening
* to port N+1 and sends the FTP command PORT N+1 to the FTP server. The
* server will then connect back to the client's specified data port from
* its local data port, which is port 20. In passive mode FTP the client
* initiates both connections to the server, solving the problem of
* firewalls filtering the incoming data port connection to the client from
* the server. When opening an FTP connection, the client opens two random
* ports locally (N>1023 and N+1). The first port contacts the server on
* port 21, but instead of then issuing a PORT command and allowing the
* server to connect back to its data port, the client will issue the PASV
* command. The result of this is that the server then opens a random
* unprivileged port (P > 1023) and sends the PORT P command back to the
* client. The client then initiates the connection from port N+1 to port
* P on the server to transfer data.
*
****************************************************************************/
@ -133,6 +133,7 @@ static int ftp_cmd_epsv(FAR struct ftpc_session_s *session,
return ERROR;
}
}
ptr++;
/* The response is then just the port number. None of the other fields
@ -170,21 +171,21 @@ static int ftp_cmd_epsv(FAR struct ftpc_session_s *session,
* Description:
* Enter passive mode using PASV command.
*
* In active mode FTP the client connects from a random port (N>1023) to the
* FTP server's command port, port 21. Then, the client starts listening to
* port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
* will then connect back to the client's specified data port from its local
* data port, which is port 20. In passive mode FTP the client initiates
* both connections to the server, solving the problem of firewalls filtering
* the incoming data port connection to the client from the server. When
* opening an FTP connection, the client opens two random ports locally
* (N>1023 and N+1). The first port contacts the server on port 21, but
* instead of then issuing a PORT command and allowing the server to connect
* back to its data port, the client will issue the PASV command. The result
* In active mode FTP the client connects from a random port (N>1023) to
* the FTP server's command port, port 21. Then the client starts listening
* to port N+1 and sends the FTP command PORT N+1 to the FTP server. The
* server will then connect back to the client's specified data port from
* its local data port, which is port 20. In passive mode FTP the client
* initiates both connections to the server, solving the problem of
* firewalls filtering the incoming data port connection to the client from
* the server. When opening an FTP connection, the client opens two random
* ports locally (N>1023 and N+1). The first port contacts the server on
* port 21, but instead of then issuing a PORT command and allowing the
* server to connect back to its data port, the client will issue the PASV
* of this is that the server then opens a random unprivileged port (P >
* 1023) and sends the PORT P command back to the client. The client then
* initiates the connection from port N+1 to port P on the server to transfer
* data.
* command. The result 1023) and sends the PORT P command back to the
* client. The client then initiates the connection from port N+1 to port P
* on the server to transfer data.
*
****************************************************************************/
@ -247,12 +248,15 @@ static int ftp_cmd_pasv(FAR struct ftpc_session_s *session,
****************************************************************************/
static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
FAR const char *relpath, FAR const char *homedir,
FAR const char *relpath,
FAR const char *homedir,
FAR const char *curdir)
{
FAR char *ptr = NULL;
/* If no relative path was provide, then use the current working directory */
/* If no relative path was provide,
* then use the current working directory
*/
if (!relpath)
{
@ -291,7 +295,7 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
else if (strncmp(relpath, "./", 2) == 0)
{
asprintf(&ptr, "%s%s", curdir, relpath+1);
asprintf(&ptr, "%s%s", curdir, relpath + 1);
}
/* Check for an absolute path */
@ -358,14 +362,14 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
/* Does this host support the PASV command */
if (!FTPC_HAS_PASV(session))
{
nerr("ERROR: Host doesn't support passive mode\n");
goto errout_with_data;
}
{
nerr("ERROR: Host doesn't support passive mode\n");
goto errout_with_data;
}
/* Configure the address to be the server address. If EPSV is used, the
* port will be populated by parsing the reply of the EPSV command. If the
* PASV command is used, the address and port will be overwritten.
* port will be populated by parsing the reply of the EPSV command. If
* the PASV command is used, the address and port will be overwritten.
*/
memcpy(&addr, &session->server, sizeof(union ftpc_sockaddr_u));
@ -409,9 +413,11 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
nerr("ERROR: ftpc_sockinit() failed: %d\n", errno);
goto errout;
}
/* Use the server IP address to find the network interface, and subsequent
* local IP address used to establish the active connection. We must send
* the IP and port to the server so that it knows how to connect.
/* Use the server IP address to find the network interface, and
* subsequent local IP address used to establish the active
* connection. We must send the IP and port to the server so that
* it knows how to connect.
*/
#ifdef CONFIG_NET_IPv6
@ -431,7 +437,7 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
if (session->server.sa.sa_family == AF_INET)
{
ret = netlib_ipv4adaptor(session->server.in4.sin_addr.s_addr,
&session->dacceptor.laddr.in4.sin_addr.s_addr);
&session->dacceptor.laddr.in4.sin_addr.s_addr);
if (ret < 0)
{
nerr("ERROR: netlib_ipv4adaptor() failed: %d\n", ret);
@ -462,7 +468,8 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
#ifdef CONFIG_NET_IPv6
if (session->dacceptor.laddr.sa.sa_family == AF_INET6)
{
if (!inet_ntop(AF_INET6, &session->dacceptor.laddr.in6.sin6_addr, ipstr, 48))
if (!inet_ntop(AF_INET6, &session->dacceptor.laddr.in6.sin6_addr,
ipstr, 48))
{
nerr("ERROR: inet_ntop failed: %d\n", errno);
goto errout_with_data;
@ -476,7 +483,8 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
#ifdef CONFIG_NET_IPv4
if (session->dacceptor.laddr.sa.sa_family == AF_INET)
{
if (!inet_ntop(AF_INET, &session->dacceptor.laddr.in4.sin_addr, ipstr, 48))
if (!inet_ntop(AF_INET, &session->dacceptor.laddr.in4.sin_addr,
ipstr, 48))
{
nerr("ERROR: inet_ntop failed: %d\n", errno);
goto errout_with_data;
@ -495,6 +503,7 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
goto errout_with_data;
}
}
return OK;
errout_with_data:
@ -535,8 +544,8 @@ int ftpc_xfrmode(struct ftpc_session_s *session, uint8_t xfrmode)
DEBUGASSERT(xfrmode != FTPC_XFRMODE_UNKNOWN);
if (session->xfrmode != xfrmode)
{
/* Send the TYPE request to control the binary flag. Parameters for the
* TYPE request include:
/* Send the TYPE request to control the binary flag.
* Parameters for the TYPE request include:
*
* A: Turn the binary flag off.
* A N: Turn the binary flag off.
@ -546,7 +555,8 @@ int ftpc_xfrmode(struct ftpc_session_s *session, uint8_t xfrmode)
* The server accepts the TYPE request with code 200.
*/
ret = ftpc_cmd(session, "TYPE %c", xfrmode == FTPC_XFRMODE_ASCII ? 'A' : 'I');
ret = ftpc_cmd(session, "TYPE %c",
xfrmode == FTPC_XFRMODE_ASCII ? 'A' : 'I');
UNUSED(ret);
session->xfrmode = xfrmode;
}
@ -580,13 +590,14 @@ int ftpc_xfrabort(FAR struct ftpc_session_s *session, FAR FILE *stream)
fds.events = POLLIN;
ret = poll(&fds, 1, 0);
if (ret > 0)
{
/* Read data from command channel */
{
/* Read data from command channel */
ninfo("Flush cmd channel data\n");
while (stream && fread(session->buffer, 1, CONFIG_FTP_BUFSIZE, stream) > 0);
return OK;
}
ninfo("Flush cmd channel data\n");
while (stream &&
fread(session->buffer, 1, CONFIG_FTP_BUFSIZE, stream) > 0);
return OK;
}
FTPC_SET_INTERRUPT(session);
@ -602,7 +613,8 @@ int ftpc_xfrabort(FAR struct ftpc_session_s *session, FAR FILE *stream)
/* Read remaining bytes from connection */
while (stream && fread(session->buffer, 1, CONFIG_FTP_BUFSIZE, stream) > 0);
while (stream &&
fread(session->buffer, 1, CONFIG_FTP_BUFSIZE, stream) > 0);
/* Get the ABORt reply */
@ -622,14 +634,14 @@ int ftpc_xfrabort(FAR struct ftpc_session_s *session, FAR FILE *stream)
fptc_getreply(session);
/* Expected replies are: or "225 Data connection open; no transfer in progress"
* "226 Closing data connection"
*/
/* Expected replies are: "226 Closing data connection" or
* "225 Data connection open; no transfer in progress"
*/
if (session->code != 226 && session->code != 225)
{
ninfo("Expected 225 or 226 reply\n");
}
if (session->code != 226 && session->code != 225)
{
ninfo("Expected 225 or 226 reply\n");
}
}
return ERROR;
@ -647,9 +659,9 @@ int ftpc_xfrabort(FAR struct ftpc_session_s *session, FAR FILE *stream)
*
****************************************************************************/
void ftpc_timeout(int argc, wdparm_t arg1, ...)
void ftpc_timeout(wdparm_t arg)
{
FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)arg1;
FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)arg;
nerr("ERROR: Timeout!\n");
DEBUGASSERT(argc == 1 && session);