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 */ /* Set up a timer to prevent hangs */
ret = wd_start(&session->wdog, session->conntimeo, ret = wd_start(&session->wdog, session->conntimeo,
ftpc_timeout, 1, (wdparm_t)session); ftpc_timeout, (wdparm_t)session);
if (ret != OK) if (ret != OK)
{ {
nerr("ERROR: wd_start() failed\n"); nerr("ERROR: wd_start() failed\n");

View File

@ -218,7 +218,7 @@ int fptc_getreply(struct ftpc_session_s *session)
if (session->replytimeo) if (session->replytimeo)
{ {
ret = wd_start(&session->wdog, 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 */ /* 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, EXTERN int ftpc_sockprintf(FAR struct ftpc_socket_s *sock,
const char *fmt, ...); const char *fmt, ...);
EXTERN void ftpc_timeout(int argc, wdparm_t arg1, ...); EXTERN void ftpc_timeout(wdparm_t arg);
/* Transfer helpers */ /* Transfer helpers */

View File

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