diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-17 23:08:24 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-17 23:08:24 +0000 |
commit | 0da3fea3b104b68f0866634e6616c75f60531506 (patch) | |
tree | d3f28342eb1fa354e4adf2e73ff71e8ed272a785 /net | |
parent | 4a77babd4294c77b873e205be3a25e9831a98079 (diff) | |
download | chromium_src-0da3fea3b104b68f0866634e6616c75f60531506.zip chromium_src-0da3fea3b104b68f0866634e6616c75f60531506.tar.gz chromium_src-0da3fea3b104b68f0866634e6616c75f60531506.tar.bz2 |
Add beginnings of a custom FTP implementation. This is built but not used or
tested yet. This is just skeleton code.
R=wtc
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/build/net.vcproj | 40 | ||||
-rw-r--r-- | net/ftp/ftp_network_layer.cc | 42 | ||||
-rw-r--r-- | net/ftp/ftp_network_layer.h | 32 | ||||
-rw-r--r-- | net/ftp/ftp_network_session.h | 26 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.cc | 203 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.h | 99 | ||||
-rw-r--r-- | net/ftp/ftp_request_info.h | 20 | ||||
-rw-r--r-- | net/ftp/ftp_response_info.h | 29 | ||||
-rw-r--r-- | net/ftp/ftp_transaction.h | 73 | ||||
-rw-r--r-- | net/ftp/ftp_transaction_factory.h | 31 | ||||
-rw-r--r-- | net/net_lib.scons | 2 |
11 files changed, 597 insertions, 0 deletions
diff --git a/net/build/net.vcproj b/net/build/net.vcproj index d04b76a..ae6c956 100644 --- a/net/build/net.vcproj +++ b/net/build/net.vcproj @@ -1045,6 +1045,46 @@ > </File> </Filter> + <Filter + Name="ftp" + > + <File + RelativePath="..\ftp\ftp_network_layer.cc" + > + </File> + <File + RelativePath="..\ftp\ftp_network_layer.h" + > + </File> + <File + RelativePath="..\ftp\ftp_network_session.h" + > + </File> + <File + RelativePath="..\ftp\ftp_network_transaction.cc" + > + </File> + <File + RelativePath="..\ftp\ftp_network_transaction.h" + > + </File> + <File + RelativePath="..\ftp\ftp_request_info.h" + > + </File> + <File + RelativePath="..\ftp\ftp_response_info.h" + > + </File> + <File + RelativePath="..\ftp\ftp_transaction.h" + > + </File> + <File + RelativePath="..\ftp\ftp_transaction_factory.h" + > + </File> + </Filter> </Files> <Globals> </Globals> diff --git a/net/ftp/ftp_network_layer.cc b/net/ftp/ftp_network_layer.cc new file mode 100644 index 0000000..ea21b4f --- /dev/null +++ b/net/ftp/ftp_network_layer.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#include "net/ftp/ftp_network_layer.h" + +#include "net/base/client_socket_factory.h" +#include "net/ftp/ftp_network_session.h" +#include "net/ftp/ftp_network_transaction.h" + +namespace net { + +FtpNetworkLayer::FtpNetworkLayer() + : suspended_(false) { + session_ = new FtpNetworkSession(); +} + +FtpNetworkLayer::~FtpNetworkLayer() { +} + +FtpTransaction* FtpNetworkLayer::CreateTransaction() { + if (suspended_) + return NULL; + + return new FtpNetworkTransaction( + session_, ClientSocketFactory::GetDefaultFactory()); +} + +AuthCache* FtpNetworkLayer::GetAuthCache() { + return session_->auth_cache(); +} + +void FtpNetworkLayer::Suspend(bool suspend) { + suspended_ = suspend; + + /* TODO(darin): We'll need this code once we have a connection manager. + if (suspend) + session_->connection_manager()->CloseIdleSockets(); + */ +} + +} // namespace net diff --git a/net/ftp/ftp_network_layer.h b/net/ftp/ftp_network_layer.h new file mode 100644 index 0000000..0f071b9 --- /dev/null +++ b/net/ftp/ftp_network_layer.h @@ -0,0 +1,32 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_NETWORK_LAYER_H_ +#define NET_FTP_FTP_NETWORK_LAYER_H_ + +#include "base/ref_counted.h" +#include "net/ftp/ftp_transaction_factory.h" + +namespace net { + +class FtpNetworkSession; + +class FtpNetworkLayer : public FtpTransactionFactory { + public: + FtpNetworkLayer(); + ~FtpNetworkLayer(); + + // FtpTransactionFactory methods: + virtual FtpTransaction* CreateTransaction(); + virtual AuthCache* GetAuthCache(); + virtual void Suspend(bool suspend); + + private: + scoped_refptr<FtpNetworkSession> session_; + bool suspended_; +}; + +} // namespace net + +#endif // NET_FTP_FTP_NETWORK_LAYER_H_ diff --git a/net/ftp/ftp_network_session.h b/net/ftp/ftp_network_session.h new file mode 100644 index 0000000..83a1cc7 --- /dev/null +++ b/net/ftp/ftp_network_session.h @@ -0,0 +1,26 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_NETWORK_SESSION_H_ +#define NET_FTP_FTP_NETWORK_SESSION_H_ + +#include "base/ref_counted.h" +#include "net/base/auth_cache.h" + +namespace net { + +// This class holds session objects used by FtpNetworkTransaction objects. +class FtpNetworkSession : public base::RefCounted<FtpNetworkSession> { + public: + FtpNetworkSession() {} + + AuthCache* auth_cache() { return &auth_cache_; } + + private: + AuthCache auth_cache_; +}; + +} // namespace net + +#endif // NET_FTP_FTP_NETWORK_SESSION_H_ diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc new file mode 100644 index 0000000..ab146f0 --- /dev/null +++ b/net/ftp/ftp_network_transaction.cc @@ -0,0 +1,203 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#include "net/ftp/ftp_network_transaction.h" + +#include "net/base/client_socket.h" +#include "net/base/net_errors.h" +#include "net/ftp/ftp_network_session.h" + +namespace net { + +FtpNetworkTransaction::FtpNetworkTransaction( + FtpNetworkSession* session, ClientSocketFactory* socket_factory) +#pragma warning(suppress: 4355) + : io_callback_(this, &FtpNetworkTransaction::OnIOComplete), + user_callback_(NULL), + session_(session), + socket_factory_(socket_factory), + next_state_(STATE_NONE) { +} + +FtpNetworkTransaction::~FtpNetworkTransaction() { +} + +void FtpNetworkTransaction::Destroy() { + delete this; +} + +int FtpNetworkTransaction::Start( + const FtpRequestInfo* request_info, CompletionCallback* callback) { + request_ = request_info; + + next_state_ = STATE_CTRL_INIT; + int rv = DoLoop(OK); + if (rv == ERR_IO_PENDING) + user_callback_ = callback; + return rv; +} + +int FtpNetworkTransaction::RestartWithAuth( + const std::wstring& username, const std::wstring& password, + CompletionCallback* callback) { + return ERR_FAILED; +} + +int FtpNetworkTransaction::Read( + char* buf, int buf_len, CompletionCallback* callback) { + return ERR_FAILED; +} + +const FtpResponseInfo* FtpNetworkTransaction::GetResponseInfo() const { + return NULL; +} + +LoadState FtpNetworkTransaction::GetLoadState() const { + return LOAD_STATE_IDLE; +} + +uint64 FtpNetworkTransaction::GetUploadProgress() const { + return 0; +} + +void FtpNetworkTransaction::DoCallback(int rv) { + DCHECK(rv != ERR_IO_PENDING); + DCHECK(user_callback_); + + // Since Run may result in Read being called, clear callback_ up front. + CompletionCallback* c = user_callback_; + user_callback_ = NULL; + c->Run(rv); +} + +void FtpNetworkTransaction::OnIOComplete(int result) { + int rv = DoLoop(result); + if (rv != ERR_IO_PENDING) + DoCallback(rv); +} + +int FtpNetworkTransaction::DoLoop(int result) { + DCHECK(next_state_ != STATE_NONE); + + int rv = result; + do { + State state = next_state_; + next_state_ = STATE_NONE; + switch (state) { + case STATE_CTRL_INIT: + DCHECK(rv == OK); + rv = DoCtrlInit(); + break; + case STATE_CTRL_INIT_COMPLETE: + rv = DoCtrlInitComplete(rv); + break; + case STATE_CTRL_RESOLVE_HOST: + DCHECK(rv == OK); + rv = DoCtrlResolveHost(); + break; + case STATE_CTRL_RESOLVE_HOST_COMPLETE: + rv = DoCtrlResolveHostComplete(rv); + break; + case STATE_CTRL_CONNECT: + DCHECK(rv == OK); + rv = DoCtrlConnect(); + break; + case STATE_CTRL_CONNECT_COMPLETE: + rv = DoCtrlConnectComplete(rv); + break; + case STATE_CTRL_WRITE: + DCHECK(rv == OK); + rv = DoCtrlWrite(); + break; + case STATE_CTRL_WRITE_COMPLETE: + rv = DoCtrlWriteComplete(rv); + break; + case STATE_CTRL_READ: + DCHECK(rv == OK); + rv = DoCtrlRead(); + break; + case STATE_CTRL_READ_COMPLETE: + rv = DoCtrlReadComplete(rv); + break; + case STATE_DATA_CONNECT: + DCHECK(rv == OK); + rv = DoDataConnect(); + break; + case STATE_DATA_CONNECT_COMPLETE: + rv = DoDataConnectComplete(rv); + break; + case STATE_DATA_READ: + DCHECK(rv == OK); + rv = DoDataRead(); + break; + case STATE_DATA_READ_COMPLETE: + rv = DoDataReadComplete(rv); + break; + default: + NOTREACHED() << "bad state"; + rv = ERR_FAILED; + break; + } + } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); + + return rv; +} + +int FtpNetworkTransaction::DoCtrlInit() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlInitComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlResolveHost() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlResolveHostComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlConnect() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlWrite() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlRead() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoCtrlReadComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoDataConnect() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoDataConnectComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoDataRead() { + return ERR_FAILED; // TODO(darin): implement me +} + +int FtpNetworkTransaction::DoDataReadComplete(int result) { + return ERR_FAILED; // TODO(darin): implement me +} + +} // namespace net diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h new file mode 100644 index 0000000..43b4712 --- /dev/null +++ b/net/ftp/ftp_network_transaction.h @@ -0,0 +1,99 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_NETWORK_TRANSACTION_H_ +#define NET_FTP_FTP_NETWORK_TRANSACTION_H_ + +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "net/ftp/ftp_response_info.h" +#include "net/ftp/ftp_transaction.h" + +namespace net { + +class ClientSocket; +class ClientSocketFactory; +class FtpNetworkSession; + +class FtpNetworkTransaction : public FtpTransaction { + public: + FtpNetworkTransaction( + FtpNetworkSession* session, ClientSocketFactory* socket_factory); + ~FtpNetworkTransaction(); + + // FtpTransactionFactory methods: + virtual void Destroy(); + virtual int Start( + const FtpRequestInfo* request_info, CompletionCallback* callback); + virtual int RestartWithAuth( + const std::wstring& username, const std::wstring& password, + CompletionCallback* callback); + virtual int Read(char* buf, int buf_len, CompletionCallback* callback); + virtual const FtpResponseInfo* GetResponseInfo() const; + virtual LoadState GetLoadState() const; + virtual uint64 GetUploadProgress() const; + + private: + void DoCallback(int result); + void OnIOComplete(int result); + + // Runs the state transition loop. + int DoLoop(int result); + + // Each of these methods corresponds to a State value. Those with an input + // argument receive the result from the previous state. If a method returns + // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the + // next state method as the result arg. + int DoCtrlInit(); + int DoCtrlInitComplete(int result); + int DoCtrlResolveHost(); + int DoCtrlResolveHostComplete(int result); + int DoCtrlConnect(); + int DoCtrlConnectComplete(int result); + int DoCtrlWrite(); + int DoCtrlWriteComplete(int result); + int DoCtrlRead(); + int DoCtrlReadComplete(int result); + int DoDataConnect(); + int DoDataConnectComplete(int result); + int DoDataRead(); + int DoDataReadComplete(int result); + + CompletionCallbackImpl<FtpNetworkTransaction> io_callback_; + CompletionCallback* user_callback_; + + scoped_refptr<FtpNetworkSession> session_; + + const FtpRequestInfo* request_; + FtpResponseInfo response_; + + ClientSocketFactory* socket_factory_; + scoped_ptr<ClientSocket> ctrl_socket_; + scoped_ptr<ClientSocket> data_socket_; + + enum State { + // Control connection states: + STATE_CTRL_INIT, + STATE_CTRL_INIT_COMPLETE, + STATE_CTRL_RESOLVE_HOST, + STATE_CTRL_RESOLVE_HOST_COMPLETE, + STATE_CTRL_CONNECT, + STATE_CTRL_CONNECT_COMPLETE, + STATE_CTRL_WRITE, + STATE_CTRL_WRITE_COMPLETE, + STATE_CTRL_READ, + STATE_CTRL_READ_COMPLETE, + // Data connection states: + STATE_DATA_CONNECT, + STATE_DATA_CONNECT_COMPLETE, + STATE_DATA_READ, + STATE_DATA_READ_COMPLETE, + STATE_NONE + }; + State next_state_; +}; + +} // namespace net + +#endif // NET_FTP_FTP_NETWORK_TRANSACTION_H_ diff --git a/net/ftp/ftp_request_info.h b/net/ftp/ftp_request_info.h new file mode 100644 index 0000000..b1d3e1c --- /dev/null +++ b/net/ftp/ftp_request_info.h @@ -0,0 +1,20 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_REQUEST_INFO_H_ +#define NET_FTP_FTP_REQUEST_INFO_H_ + +class FtpRequestInfo { + public: + // The requested URL. + GURL url; + + // Any upload data. + scoped_refptr<UploadData> upload_data; + + // Any load flags (see load_flags.h). + int load_flags; +}; + +#endif // NET_FTP_FTP_REQUEST_INFO_H_ diff --git a/net/ftp/ftp_response_info.h b/net/ftp/ftp_response_info.h new file mode 100644 index 0000000..398f050 --- /dev/null +++ b/net/ftp/ftp_response_info.h @@ -0,0 +1,29 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_RESPONSE_INFO_H_ +#define NET_FTP_FTP_RESPONSE_INFO_H_ + +#include "net/base/auth.h" + +namespace net { + +class FtpResponseInfo { + public: + // Non-null when authentication is required. + scoped_refptr<AuthChallengeInfo> auth_challenge; + + // The length of the response. -1 means unspecified. + int64 content_length; + + // True if the response data is of a directory listing. + bool is_directory_listing; + + FtpResponseInfo() : content_length(-1), is_directory_listing(false) { + } +}; + +} // namespace net + +#endif // NET_FTP_FTP_RESPONSE_INFO_H_ diff --git a/net/ftp/ftp_transaction.h b/net/ftp/ftp_transaction.h new file mode 100644 index 0000000..90fbf25 --- /dev/null +++ b/net/ftp/ftp_transaction.h @@ -0,0 +1,73 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_TRANSACTION_H_ +#define NET_FTP_FTP_TRANSACTION_H_ + +#include "net/base/completion_callback.h" +#include "net/base/load_states.h" + +namespace net { + +class FtpRequestInfo; +class FtpResponseInfo; + +// Represents a single FTP transaction. +class FtpTransaction { + public: + // Stops any pending IO and destroys the transaction object. + virtual void Destroy() = 0; + + // Starts the FTP transaction (i.e., sends the FTP request). + // + // Returns OK if the transaction could be started synchronously, which means + // that the request was served from the cache (only supported for directory + // listings). ERR_IO_PENDING is returned to indicate that the + // CompletionCallback will be notified once response info is available or if + // an IO error occurs. Any other return value indicates that the transaction + // could not be started. + // + // Regardless of the return value, the caller is expected to keep the + // request_info object alive until Destroy is called on the transaction. + // + // NOTE: The transaction is not responsible for deleting the callback object. + // + virtual int Start(const FtpRequestInfo* request_info, + CompletionCallback* callback) = 0; + + // Restarts the FTP transaction with authentication credentials. + virtual int RestartWithAuth(const std::wstring& username, + const std::wstring& password, + CompletionCallback* callback) = 0; + + // Once response info is available for the transaction, response data may be + // read by calling this method. + // + // Response data is copied into the given buffer and the number of bytes + // copied is returned. ERR_IO_PENDING is returned if response data is not + // yet available. The CompletionCallback is notified when the data copy + // completes, and it is passed the number of bytes that were successfully + // copied. Or, if a read error occurs, the CompletionCallback is notified of + // the error. Any other negative return value indicates that the transaction + // could not be read. + // + // NOTE: The transaction is not responsible for deleting the callback object. + // + virtual int Read(char* buf, int buf_len, CompletionCallback* callback) = 0; + + // Returns the response info for this transaction or NULL if the response + // info is not available. + virtual const FtpResponseInfo* GetResponseInfo() const = 0; + + // Returns the load state for this transaction. + virtual LoadState GetLoadState() const = 0; + + // Returns the upload progress in bytes. If there is no upload data, + // zero will be returned. This does not include the request headers. + virtual uint64 GetUploadProgress() const = 0; +}; + +} // namespace net + +#endif // NET_FTP_FTP_TRANSACTION_H_ diff --git a/net/ftp/ftp_transaction_factory.h b/net/ftp/ftp_transaction_factory.h new file mode 100644 index 0000000..67af645 --- /dev/null +++ b/net/ftp/ftp_transaction_factory.h @@ -0,0 +1,31 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef NET_FTP_FTP_TRANSACTION_FACTORY_H_ +#define NET_FTP_FTP_TRANSACTION_FACTORY_H_ + +namespace net { + +class AuthCache; +class FtpTransaction; + +// An interface to a class that can create FtpTransaction objects. +class FtpTransactionFactory { + public: + virtual ~FtpTransactionFactory() {} + + // Creates a FtpTransaction object. + virtual FtpTransaction* CreateTransaction() = 0; + + // Returns the associated FTP auth cache if any (may be NULL). + virtual AuthCache* GetAuthCache() = 0; + + // Suspends the creation of new transactions. If |suspend| is false, creation + // of new transactions is resumed. + virtual void Suspend(bool suspend) = 0; +}; + +} // namespace net + +#endif // NET_FTP_FTP_TRANSACTION_FACTORY_H_ diff --git a/net/net_lib.scons b/net/net_lib.scons index 972dd31..61a8a10 100644 --- a/net/net_lib.scons +++ b/net/net_lib.scons @@ -63,6 +63,8 @@ input_files = [ 'disk_cache/stats.cc', 'disk_cache/stats_histogram.cc', 'disk_cache/trace.cc', + 'ftp/ftp_network_layer.cc', + 'ftp/ftp_network_transaction.cc', 'http/cert_status_cache.cc', 'http/http_auth.cc', 'http/http_auth_cache.cc', |