iPXE
|
File transfer protocol. More...
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include <byteswap.h>
#include <ipxe/socket.h>
#include <ipxe/tcpip.h>
#include <ipxe/in.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <ipxe/features.h>
#include <ipxe/ftp.h>
Go to the source code of this file.
Data Structures | |
struct | ftp_request |
An FTP request. More... | |
struct | ftp_control_string |
An FTP control channel string. More... | |
Enumerations | |
enum | ftp_state { FTP_CONNECT = 0, FTP_USER, FTP_PASS, FTP_TYPE, FTP_SIZE, FTP_PASV, FTP_RETR, FTP_WAIT, FTP_QUIT, FTP_DONE } |
FTP states. More... | |
Functions | |
FEATURE (FEATURE_PROTOCOL, "FTP", DHCP_EB_FEATURE_FTP, 1) | |
static void | ftp_free (struct refcnt *refcnt) |
Free FTP request. More... | |
static void | ftp_done (struct ftp_request *ftp, int rc) |
Mark FTP operation as complete. More... | |
static const char * | ftp_uri_path (struct ftp_request *ftp) |
Retrieve FTP pathname. More... | |
static const char * | ftp_user (struct ftp_request *ftp) |
Retrieve FTP user. More... | |
static const char * | ftp_password (struct ftp_request *ftp) |
Retrieve FTP password. More... | |
static void | ftp_parse_value (char **text, uint8_t *value, size_t len) |
Parse FTP byte sequence value. More... | |
static void | ftp_next_state (struct ftp_request *ftp) |
Move to next state and send the appropriate FTP control string. More... | |
static void | ftp_reply (struct ftp_request *ftp) |
Handle an FTP control channel response. More... | |
static int | ftp_control_deliver (struct ftp_request *ftp, struct io_buffer *iobuf, struct xfer_metadata *meta __unused) |
Handle new data arriving on FTP control channel. More... | |
static void | ftp_data_closed (struct ftp_request *ftp, int rc) |
Handle FTP data channel being closed. More... | |
static int | ftp_check_string (const char *string) |
Check validity of FTP control channel string. More... | |
static int | ftp_open (struct interface *xfer, struct uri *uri) |
Initiate an FTP connection. More... | |
Variables | |
static struct ftp_control_string | ftp_strings [] |
FTP control channel strings. More... | |
static struct interface_operation | ftp_control_operations [] |
FTP control channel interface operations. More... | |
static struct interface_descriptor | ftp_control_desc |
FTP control channel interface descriptor. More... | |
static struct interface_operation | ftp_data_operations [] |
FTP data channel interface operations. More... | |
static struct interface_descriptor | ftp_data_desc |
FTP data channel interface descriptor. More... | |
static struct interface_operation | ftp_xfer_operations [] |
FTP data transfer interface operations. More... | |
static struct interface_descriptor | ftp_xfer_desc |
FTP data transfer interface descriptor. More... | |
struct uri_opener ftp_uri_opener | __uri_opener |
FTP URI opener. More... | |
File transfer protocol.
Definition in file ftp.c.
enum ftp_state |
FEATURE | ( | FEATURE_PROTOCOL | , |
"FTP" | , | ||
DHCP_EB_FEATURE_FTP | , | ||
1 | |||
) |
|
static |
Free FTP request.
refcnt | Reference counter |
Definition at line 101 of file ftp.c.
References container_of, DBGC, free, ftp_request::uri, and uri_put().
Referenced by ftp_open().
|
static |
Mark FTP operation as complete.
ftp | FTP request |
rc | Return status code |
Definition at line 117 of file ftp.c.
References ftp_request::control, ftp_request::data, DBGC, intf_shutdown(), rc, strerror(), and ftp_request::xfer.
Referenced by ftp_data_closed(), ftp_open(), and ftp_reply().
|
static |
Retrieve FTP pathname.
ftp | FTP request |
path | FTP pathname |
Definition at line 151 of file ftp.c.
References uri::path, and ftp_request::uri.
|
static |
Retrieve FTP user.
ftp | FTP request |
user | FTP user |
Definition at line 161 of file ftp.c.
References ftp_request::uri, and uri::user.
|
static |
Retrieve FTP password.
ftp | FTP request |
password | FTP password |
Definition at line 172 of file ftp.c.
References uri::password, and ftp_request::uri.
Parse FTP byte sequence value.
text | Text string |
value | Value buffer |
len | Length of value buffer |
This parses an FTP byte sequence value (e.g. the "aaa,bbb,ccc,ddd" form for IP addresses in PORT commands) into a byte sequence. *text
will be updated to point beyond the end of the parsed byte sequence.
This function is safe in the presence of malformed data, though the output is undefined.
Definition at line 206 of file ftp.c.
References len, strtoul(), and value.
Referenced by ftp_reply().
|
static |
Move to next state and send the appropriate FTP control string.
ftp | FTP request |
Definition at line 220 of file ftp.c.
References ftp_request::control, DBGC, FTP_DONE, ftp_strings, ftp_control_string::literal, ftp_request::state, ftp_control_string::variable, and xfer_printf().
Referenced by ftp_data_closed(), and ftp_reply().
|
static |
Handle an FTP control channel response.
ftp | FTP request |
This is called once we have received a complete response line.
Definition at line 247 of file ftp.c.
References AF_INET, ftp_request::data, DBGC, EPROTO, ftp_request::filesize, ftp_done(), ftp_next_state(), ftp_parse_value(), FTP_PASV, FTP_SIZE, FTP_USER, NULL, ftp_request::passive_text, rc, sa, sin, SOCK_STREAM, ftp_request::state, ftp_request::status_text, strtoul(), ftp_request::xfer, xfer_open_socket(), and xfer_seek().
Referenced by ftp_control_deliver().
|
static |
Handle new data arriving on FTP control channel.
ftp | FTP request |
iob | I/O buffer |
meta | Data transfer metadata |
rc | Return status code |
Data is collected until a complete line is received, at which point its information is passed to ftp_reply().
Definition at line 339 of file ftp.c.
References c, data, io_buffer::data, ftp_request::filesize, free_iob(), FTP_PASV, ftp_reply(), FTP_SIZE, iob_len(), len, ftp_request::passive_text, ftp_request::recvbuf, ftp_request::recvsize, ftp_request::state, and ftp_request::status_text.
|
static |
Handle FTP data channel being closed.
ftp | FTP request |
rc | Reason for closure |
When the data channel is closed, the control channel should be left alone; the server will send a completion message via the control channel which we'll pick up.
If the data channel is closed due to an error, we abort the request.
Definition at line 418 of file ftp.c.
References DBGC, ftp_done(), ftp_next_state(), rc, and strerror().
|
static |
Initiate an FTP connection.
xfer | Data transfer interface |
uri | Uniform Resource Identifier |
rc | Return status code |
Definition at line 489 of file ftp.c.
References ftp_request::control, ftp_request::data, DBGC, EINVAL, ENOMEM, ftp_check_string(), ftp_control_desc, ftp_data_desc, ftp_done(), ftp_free(), FTP_PORT, ftp_xfer_desc, uri::host, htons, intf_init(), intf_plug_plug(), memset(), NULL, uri::password, uri::path, rc, ftp_request::recvbuf, ftp_request::recvsize, ref_init, ref_put, ftp_request::refcnt, SOCK_STREAM, sockaddr_tcpip::st_port, ftp_request::status_text, strerror(), ftp_request::uri, uri_get(), uri_port(), uri::user, ftp_request::xfer, xfer_open_named_socket(), and zalloc().
|
static |
FTP control channel strings.
Definition at line 178 of file ftp.c.
Referenced by ftp_next_state().
|
static |
FTP control channel interface operations.
|
static |
FTP control channel interface descriptor.
Definition at line 397 of file ftp.c.
Referenced by ftp_open().
|
static |
FTP data channel interface operations.
|
static |
FTP data channel interface descriptor.
Definition at line 437 of file ftp.c.
Referenced by ftp_open().
|
static |
FTP data transfer interface operations.
|
static |
FTP data transfer interface descriptor.
Definition at line 453 of file ftp.c.
Referenced by ftp_open().