2006-04-30 14:02:07 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <vsprintf.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2006-06-19 17:46:58 +02:00
|
|
|
#include <gpxe/async.h>
|
2007-01-11 05:51:20 +01:00
|
|
|
#include <gpxe/buffer.h>
|
2007-01-15 10:58:26 +01:00
|
|
|
#include <gpxe/uri.h>
|
2006-04-30 14:02:07 +02:00
|
|
|
#include <gpxe/ftp.h>
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* File transfer protocol
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* FTP control channel
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-01-15 10:58:26 +01:00
|
|
|
/** FTP control channel strings
|
2006-04-30 17:23:29 +02:00
|
|
|
*
|
2007-01-15 10:58:26 +01:00
|
|
|
* These are used as printf() format strings. Since only one of them
|
|
|
|
* (RETR) takes an argument, we always supply that argument to the
|
|
|
|
* snprintf() call.
|
2006-04-30 17:23:29 +02:00
|
|
|
*/
|
2007-01-15 10:58:26 +01:00
|
|
|
static const char * ftp_strings[] = {
|
|
|
|
[FTP_CONNECT] = "",
|
|
|
|
[FTP_USER] = "USER anonymous\r\n",
|
|
|
|
[FTP_PASS] = "PASS etherboot@etherboot.org\r\n",
|
|
|
|
[FTP_TYPE] = "TYPE I\r\n",
|
|
|
|
[FTP_PASV] = "PASV\r\n",
|
|
|
|
[FTP_RETR] = "RETR %s\r\n",
|
|
|
|
[FTP_QUIT] = "QUIT\r\n",
|
|
|
|
[FTP_DONE] = "",
|
|
|
|
};
|
2006-04-30 14:02:07 +02:00
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
2006-12-28 00:09:46 +01:00
|
|
|
* Get FTP request from control TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
* @ret ftp FTP request
|
|
|
|
*/
|
2006-12-28 00:09:46 +01:00
|
|
|
static inline struct ftp_request * tcp_to_ftp ( struct tcp_application *app ) {
|
|
|
|
return container_of ( app, struct ftp_request, tcp );
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-12-05 23:53:49 +01:00
|
|
|
/**
|
2006-12-28 00:09:46 +01:00
|
|
|
* Mark FTP operation as complete
|
2006-12-05 23:53:49 +01:00
|
|
|
*
|
|
|
|
* @v ftp FTP request
|
|
|
|
* @v rc Return status code
|
|
|
|
*/
|
2006-12-28 00:09:46 +01:00
|
|
|
static void ftp_done ( struct ftp_request *ftp, int rc ) {
|
2006-12-05 20:07:47 +01:00
|
|
|
|
2006-12-29 15:09:23 +01:00
|
|
|
DBGC ( ftp, "FTP %p completed with status %d\n", ftp, rc );
|
2006-12-05 20:07:47 +01:00
|
|
|
|
2006-12-28 00:09:46 +01:00
|
|
|
/* Close both TCP connections */
|
|
|
|
tcp_close ( &ftp->tcp );
|
|
|
|
tcp_close ( &ftp->tcp_data );
|
2006-12-05 23:53:49 +01:00
|
|
|
|
2006-12-28 00:09:46 +01:00
|
|
|
/* Mark asynchronous operation as complete */
|
2007-01-15 09:49:10 +01:00
|
|
|
async_done ( &ftp->async, rc );
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 17:23:29 +02:00
|
|
|
/**
|
|
|
|
* Parse FTP byte sequence value
|
|
|
|
*
|
|
|
|
* @v text Text string
|
|
|
|
* @v value Value buffer
|
|
|
|
* @v 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. @c
|
|
|
|
* *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.
|
|
|
|
*/
|
|
|
|
static void ftp_parse_value ( char **text, uint8_t *value, size_t len ) {
|
|
|
|
do {
|
|
|
|
*(value++) = strtoul ( *text, text, 10 );
|
|
|
|
if ( **text )
|
|
|
|
(*text)++;
|
|
|
|
} while ( --len );
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 17:23:29 +02:00
|
|
|
/**
|
2006-04-30 18:59:45 +02:00
|
|
|
* Handle an FTP control channel response
|
2006-04-30 17:23:29 +02:00
|
|
|
*
|
|
|
|
* @v ftp FTP request
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* This is called once we have received a complete response line.
|
2006-04-30 17:23:29 +02:00
|
|
|
*/
|
|
|
|
static void ftp_reply ( struct ftp_request *ftp ) {
|
2006-04-30 14:02:07 +02:00
|
|
|
char status_major = ftp->status_text[0];
|
|
|
|
|
2006-12-29 15:09:23 +01:00
|
|
|
DBGC ( ftp, "FTP %p received status %s\n", ftp, ftp->status_text );
|
2006-12-05 23:53:49 +01:00
|
|
|
|
2006-04-30 17:23:29 +02:00
|
|
|
/* Ignore "intermediate" responses (1xx codes) */
|
2006-04-30 14:02:07 +02:00
|
|
|
if ( status_major == '1' )
|
|
|
|
return;
|
|
|
|
|
2006-04-30 17:23:29 +02:00
|
|
|
/* Anything other than success (2xx) or, in the case of a
|
|
|
|
* repsonse to a "USER" command, a password prompt (3xx), is a
|
|
|
|
* fatal error.
|
|
|
|
*/
|
|
|
|
if ( ! ( ( status_major == '2' ) ||
|
2006-12-28 00:09:46 +01:00
|
|
|
( ( status_major == '3' ) && ( ftp->state == FTP_USER ) ) ) ){
|
|
|
|
/* Flag protocol error and close connections */
|
|
|
|
ftp_done ( ftp, -EPROTO );
|
|
|
|
}
|
2006-04-30 14:02:07 +02:00
|
|
|
|
|
|
|
/* Open passive connection when we get "PASV" response */
|
|
|
|
if ( ftp->state == FTP_PASV ) {
|
2006-04-30 17:23:29 +02:00
|
|
|
char *ptr = ftp->passive_text;
|
2006-12-28 00:09:46 +01:00
|
|
|
union {
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct sockaddr_tcpip st;
|
|
|
|
} sa;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
sa.sin.sin_family = AF_INET;
|
|
|
|
ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_addr,
|
|
|
|
sizeof ( sa.sin.sin_addr ) );
|
|
|
|
ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_port,
|
|
|
|
sizeof ( sa.sin.sin_port ) );
|
|
|
|
if ( ( rc = tcp_connect ( &ftp->tcp_data, &sa.st, 0 ) ) != 0 ){
|
2006-12-29 15:09:23 +01:00
|
|
|
DBGC ( ftp, "FTP %p could not make data connection\n",
|
|
|
|
ftp );
|
2006-12-28 00:09:46 +01:00
|
|
|
ftp_done ( ftp, rc );
|
|
|
|
return;
|
|
|
|
}
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to next state */
|
|
|
|
if ( ftp->state < FTP_DONE )
|
|
|
|
ftp->state++;
|
|
|
|
ftp->already_sent = 0;
|
2006-12-05 23:53:49 +01:00
|
|
|
|
|
|
|
if ( ftp->state < FTP_DONE ) {
|
2006-12-29 15:09:23 +01:00
|
|
|
DBGC ( ftp, "FTP %p sending ", ftp );
|
2007-01-15 10:58:26 +01:00
|
|
|
DBGC ( ftp, ftp_strings[ftp->state], ftp->uri->path );
|
2006-12-05 23:53:49 +01:00
|
|
|
}
|
|
|
|
|
2006-04-30 14:02:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
|
|
|
* Handle new data arriving on FTP control channel
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
* @v data New data
|
|
|
|
* @v len Length of new data
|
|
|
|
*
|
|
|
|
* Data is collected until a complete line is received, at which point
|
|
|
|
* its information is passed to ftp_reply().
|
|
|
|
*/
|
2006-12-28 00:09:46 +01:00
|
|
|
static void ftp_newdata ( struct tcp_application *app,
|
2006-04-30 14:02:07 +02:00
|
|
|
void *data, size_t len ) {
|
2006-12-28 00:09:46 +01:00
|
|
|
struct ftp_request *ftp = tcp_to_ftp ( app );
|
2006-04-30 17:23:29 +02:00
|
|
|
char *recvbuf = ftp->recvbuf;
|
|
|
|
size_t recvsize = ftp->recvsize;
|
2006-04-30 14:02:07 +02:00
|
|
|
char c;
|
2006-04-30 17:23:29 +02:00
|
|
|
|
|
|
|
while ( len-- ) {
|
|
|
|
c = * ( ( char * ) data++ );
|
|
|
|
switch ( c ) {
|
|
|
|
case '\r' :
|
|
|
|
case '\n' :
|
|
|
|
/* End of line: call ftp_reply() to handle
|
|
|
|
* completed reply. Avoid calling ftp_reply()
|
|
|
|
* twice if we receive both \r and \n.
|
|
|
|
*/
|
|
|
|
if ( recvsize == 0 )
|
2006-04-30 14:02:07 +02:00
|
|
|
ftp_reply ( ftp );
|
2006-04-30 17:23:29 +02:00
|
|
|
/* Start filling up the status code buffer */
|
|
|
|
recvbuf = ftp->status_text;
|
|
|
|
recvsize = sizeof ( ftp->status_text ) - 1;
|
|
|
|
break;
|
|
|
|
case '(' :
|
|
|
|
/* Start filling up the passive parameter buffer */
|
|
|
|
recvbuf = ftp->passive_text;
|
|
|
|
recvsize = sizeof ( ftp->passive_text ) - 1;
|
|
|
|
break;
|
|
|
|
case ')' :
|
|
|
|
/* Stop filling the passive parameter buffer */
|
|
|
|
recvsize = 0;
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
/* Fill up buffer if applicable */
|
|
|
|
if ( recvsize > 0 ) {
|
|
|
|
*(recvbuf++) = c;
|
|
|
|
recvsize--;
|
|
|
|
}
|
|
|
|
break;
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
}
|
2006-04-30 17:23:29 +02:00
|
|
|
|
|
|
|
/* Store for next invocation */
|
|
|
|
ftp->recvbuf = recvbuf;
|
|
|
|
ftp->recvsize = recvsize;
|
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
|
|
|
* Handle acknowledgement of data sent on FTP control channel
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
*/
|
2006-12-28 00:09:46 +01:00
|
|
|
static void ftp_acked ( struct tcp_application *app, size_t len ) {
|
|
|
|
struct ftp_request *ftp = tcp_to_ftp ( app );
|
2006-04-30 17:23:29 +02:00
|
|
|
|
|
|
|
/* Mark off ACKed portion of the currently-transmitted data */
|
|
|
|
ftp->already_sent += len;
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
|
|
|
* Construct data to send on FTP control channel
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-06-18 01:20:54 +02:00
|
|
|
* @v buf Temporary data buffer
|
|
|
|
* @v len Length of temporary data buffer
|
2006-04-30 18:59:45 +02:00
|
|
|
*/
|
2006-12-28 00:09:46 +01:00
|
|
|
static void ftp_senddata ( struct tcp_application *app,
|
2006-06-18 01:20:54 +02:00
|
|
|
void *buf, size_t len ) {
|
2006-12-28 00:09:46 +01:00
|
|
|
struct ftp_request *ftp = tcp_to_ftp ( app );
|
2006-04-30 14:02:07 +02:00
|
|
|
|
2006-04-30 17:23:29 +02:00
|
|
|
/* Send the as-yet-unACKed portion of the string for the
|
|
|
|
* current state.
|
|
|
|
*/
|
2007-01-15 10:58:26 +01:00
|
|
|
len = snprintf ( buf, len, ftp_strings[ftp->state], ftp->uri->path );
|
2006-12-28 00:09:46 +01:00
|
|
|
tcp_send ( app, buf + ftp->already_sent, len - ftp->already_sent );
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
|
|
|
* Handle control channel being closed
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
*
|
|
|
|
* When the control channel is closed, the data channel must also be
|
|
|
|
* closed, if it is currently open.
|
|
|
|
*/
|
2007-01-11 05:51:20 +01:00
|
|
|
static void ftp_closed ( struct tcp_application *app, int rc ) {
|
2006-12-28 00:09:46 +01:00
|
|
|
struct ftp_request *ftp = tcp_to_ftp ( app );
|
2006-04-30 17:23:29 +02:00
|
|
|
|
2007-01-11 05:51:20 +01:00
|
|
|
DBGC ( ftp, "FTP %p control connection closed: %s\n",
|
|
|
|
ftp, strerror ( rc ) );
|
2006-12-05 23:53:49 +01:00
|
|
|
|
2006-12-28 00:09:46 +01:00
|
|
|
/* Complete FTP operation */
|
2007-01-11 05:51:20 +01:00
|
|
|
ftp_done ( ftp, rc );
|
2006-04-30 17:23:29 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/** FTP control channel operations */
|
2006-04-30 14:02:07 +02:00
|
|
|
static struct tcp_operations ftp_tcp_operations = {
|
|
|
|
.closed = ftp_closed,
|
|
|
|
.acked = ftp_acked,
|
|
|
|
.newdata = ftp_newdata,
|
|
|
|
.senddata = ftp_senddata,
|
|
|
|
};
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2006-04-30 20:19:39 +02:00
|
|
|
* FTP data channel
|
2006-04-30 18:59:45 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2006-12-28 00:09:46 +01:00
|
|
|
* Get FTP request from data TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
* @ret ftp FTP request
|
|
|
|
*/
|
2006-04-30 17:23:29 +02:00
|
|
|
static inline struct ftp_request *
|
2006-12-28 00:09:46 +01:00
|
|
|
tcp_to_ftp_data ( struct tcp_application *app ) {
|
|
|
|
return container_of ( app, struct ftp_request, tcp_data );
|
2006-04-30 17:23:29 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
|
|
|
* Handle data channel being closed
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-01-11 05:51:20 +01:00
|
|
|
static void ftp_data_closed ( struct tcp_application *app, int rc ) {
|
2006-12-28 00:09:46 +01:00
|
|
|
struct ftp_request *ftp = tcp_to_ftp_data ( app );
|
2006-12-05 23:53:49 +01:00
|
|
|
|
2007-01-11 05:51:20 +01:00
|
|
|
DBGC ( ftp, "FTP %p data connection closed: %s\n",
|
|
|
|
ftp, strerror ( rc ) );
|
2006-12-05 20:07:47 +01:00
|
|
|
|
|
|
|
/* If there was an error, close control channel and record status */
|
2007-01-11 05:51:20 +01:00
|
|
|
if ( rc )
|
|
|
|
ftp_done ( ftp, rc );
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/**
|
|
|
|
* Handle new data arriving on the FTP data channel
|
|
|
|
*
|
2006-12-28 00:09:46 +01:00
|
|
|
* @v app TCP application
|
2006-04-30 18:59:45 +02:00
|
|
|
* @v data New data
|
|
|
|
* @v len Length of new data
|
|
|
|
*/
|
2006-12-28 00:09:46 +01:00
|
|
|
static void ftp_data_newdata ( struct tcp_application *app,
|
2006-04-30 14:02:07 +02:00
|
|
|
void *data, size_t len ) {
|
2006-12-28 00:09:46 +01:00
|
|
|
struct ftp_request *ftp = tcp_to_ftp_data ( app );
|
2007-01-11 05:51:20 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Fill data buffer */
|
|
|
|
if ( ( rc = fill_buffer ( ftp->buffer, data,
|
2007-01-12 18:16:46 +01:00
|
|
|
ftp->buffer->fill, len ) ) != 0 ){
|
2007-01-11 05:51:20 +01:00
|
|
|
DBGC ( ftp, "FTP %p failed to fill data buffer: %s\n",
|
|
|
|
ftp, strerror ( rc ) );
|
|
|
|
ftp_done ( ftp, rc );
|
|
|
|
return;
|
|
|
|
}
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|
|
|
|
|
2006-04-30 18:59:45 +02:00
|
|
|
/** FTP data channel operations */
|
2006-04-30 14:02:07 +02:00
|
|
|
static struct tcp_operations ftp_data_tcp_operations = {
|
2006-04-30 18:59:45 +02:00
|
|
|
.closed = ftp_data_closed,
|
2006-04-30 14:02:07 +02:00
|
|
|
.newdata = ftp_data_newdata,
|
|
|
|
};
|
|
|
|
|
2006-04-30 20:19:39 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* API
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-01-15 10:58:26 +01:00
|
|
|
/**
|
|
|
|
* Reap asynchronous operation
|
|
|
|
*
|
|
|
|
* @v async Asynchronous operation
|
|
|
|
*/
|
|
|
|
static void ftp_reap ( struct async *async ) {
|
|
|
|
struct ftp_request *ftp =
|
|
|
|
container_of ( async, struct ftp_request, async );
|
|
|
|
|
|
|
|
free ( ftp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** FTP asynchronous operations */
|
|
|
|
static struct async_operations ftp_async_operations = {
|
|
|
|
.reap = ftp_reap,
|
|
|
|
};
|
|
|
|
|
|
|
|
#warning "Quick name resolution hack"
|
|
|
|
#include <byteswap.h>
|
|
|
|
|
2006-04-30 14:02:07 +02:00
|
|
|
/**
|
|
|
|
* Initiate an FTP connection
|
|
|
|
*
|
2007-01-15 10:58:26 +01:00
|
|
|
* @v uri Uniform Resource Identifier
|
|
|
|
* @v buffer Buffer into which to download file
|
|
|
|
* @v parent Parent asynchronous operation
|
|
|
|
* @ret rc Return status code
|
2006-04-30 14:02:07 +02:00
|
|
|
*/
|
2007-01-15 10:58:26 +01:00
|
|
|
int ftp_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
|
|
|
|
struct ftp_request *ftp = NULL;
|
2006-12-28 00:09:46 +01:00
|
|
|
int rc;
|
|
|
|
|
2007-01-15 10:58:26 +01:00
|
|
|
/* Sanity checks */
|
|
|
|
if ( ! uri->path ) {
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
2006-12-05 23:53:49 +01:00
|
|
|
|
2007-01-15 10:58:26 +01:00
|
|
|
/* Allocate and populate FTP structure */
|
|
|
|
ftp = malloc ( sizeof ( *ftp ) );
|
|
|
|
if ( ! ftp ) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
memset ( ftp, 0, sizeof ( *ftp ) );
|
|
|
|
ftp->uri = uri;
|
|
|
|
ftp->buffer = buffer;
|
2007-01-11 05:51:20 +01:00
|
|
|
ftp->state = FTP_CONNECT;
|
|
|
|
ftp->already_sent = 0;
|
2006-04-30 14:02:07 +02:00
|
|
|
ftp->recvbuf = ftp->status_text;
|
|
|
|
ftp->recvsize = sizeof ( ftp->status_text ) - 1;
|
2007-01-11 05:51:20 +01:00
|
|
|
ftp->tcp.tcp_op = &ftp_tcp_operations;
|
|
|
|
ftp->tcp_data.tcp_op = &ftp_data_tcp_operations;
|
2006-12-28 00:09:46 +01:00
|
|
|
|
2007-01-15 10:58:26 +01:00
|
|
|
#warning "Quick name resolution hack"
|
|
|
|
union {
|
|
|
|
struct sockaddr_tcpip st;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
} server;
|
|
|
|
server.sin.sin_port = htons ( FTP_PORT );
|
|
|
|
server.sin.sin_family = AF_INET;
|
|
|
|
if ( inet_aton ( uri->host, &server.sin.sin_addr ) == 0 ) {
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBGC ( ftp, "FTP %p fetching %s\n", ftp, ftp->uri->path );
|
|
|
|
|
|
|
|
if ( ( rc = tcp_connect ( &ftp->tcp, &server.st, 0 ) ) != 0 )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
async_init ( &ftp->async, &ftp_async_operations, parent );
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
DBGC ( ftp, "FTP %p could not create request: %s\n",
|
|
|
|
ftp, strerror ( rc ) );
|
|
|
|
free ( ftp );
|
|
|
|
return rc;
|
2006-04-30 14:02:07 +02:00
|
|
|
}
|