1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright (c) 2006-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_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
#define NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
#include "net/url_request/url_request_inet_job.h"
// A basic FTP job that handles download files and showing directory listings.
class URLRequestFtpJob : public URLRequestInetJob {
public:
static URLRequestJob* Factory(URLRequest* request, const std::string& scheme);
virtual ~URLRequestFtpJob();
// URLRequestJob methods:
virtual void Start();
virtual bool GetMimeType(std::string* mime_type);
// URLRequestInetJob methods:
virtual void OnIOComplete(const AsyncResult& result);
protected:
URLRequestFtpJob(URLRequest* request);
// Starts the WinInet request.
virtual void SendRequest();
virtual int CallInternetRead(char* dest, int dest_size, int *bytes_read);
virtual bool GetReadBytes(const AsyncResult& result, int* bytes_read);
virtual void OnCancelAuth();
virtual void OnSetAuth();
virtual bool NeedsAuth();
virtual void GetAuthChallengeInfo(scoped_refptr<net::AuthChallengeInfo>*);
virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
private:
// Called after InternetConnect successfully connects to server.
void OnConnect();
// Called after FtpSetCurrentDirectory attempts to change current dir.
void OnSetCurrentDirectory(DWORD last_error);
// Requests the next file in the directory listing from WinInet.
void FindNextFile();
// Called when the first file in a directory listing is available.
void OnFindFirstFile(DWORD last_error);
// Called when a file in a directory listing is available.
void OnFindFile(DWORD last_error);
// Call this when starting a directory listing to setup the html.
void OnStartDirectoryTraversal();
// Call this at the end of a directory listing to complete the html.
void OnFinishDirectoryTraversal();
// If given data, writes it to the directory listing html. If
// call_io_complete is true, will also notify the parent class that we wrote
// data in the given buffer.
int WriteData(const std::string* data, bool call_io_complete);
// Continuation function for calling OnIOComplete through the message loop.
virtual void ContinueIOComplete(int bytes_written);
// Continuation function for calling NotifyHeadersComplete through
//the message loop
virtual void ContinueNotifyHeadersComplete();
typedef enum {
START = 0x200, // initial state of the ftp job
CONNECTING, // opening the url
SETTING_CUR_DIRECTORY, // attempting to change current dir to match request
FINDING_FIRST_FILE, // retrieving first file information in cur dir (by FtpFindFirstFile)
GETTING_DIRECTORY, // retrieving the directory listing (if directory)
GETTING_FILE_HANDLE, // initiate access to file by call to FtpOpenFile (if file)
GETTING_FILE, // retrieving the file (if file)
DONE // URLRequestInetJob is reading the response now
} FtpJobState;
// The FtpJob has several asynchronous operations which happen
// in sequence. The state keeps track of which asynchronous IO
// is pending at any given point in time.
FtpJobState state_;
// In IE 4 and before, this pointer passed to asynchronous InternetReadFile
// calls is where the number of read bytes is written to.
DWORD bytes_read_;
bool is_directory_; // does the url point to a file or directory
WIN32_FIND_DATAA find_data_;
std::string directory_html_; // if url is directory holds html
// When building a directory listing, we need to temporarily hold on to the
// buffer in between the time a Read() call comes in and we get the file
// entry from WinInet.
char* dest_;
int dest_size_;
DISALLOW_EVIL_CONSTRUCTORS(URLRequestFtpJob);
};
#endif // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
|