15#include "wvistreamlist.h"
16#include "wvstreamclone.h"
18#include "wvhashtable.h"
19#include "wvbufstream.h"
28static const WvString DEFAULT_ANON_PW(
"weasels@");
34 WvHTTPHeader(WvStringParm _name, WvStringParm _value)
35 : name(_name), value(_value)
48 WvUrlStream *instream;
49 WvBufUrlStream *outstream;
58 WvUrlRequest(WvStringParm _url, WvStringParm _method, WvStringParm _headers,
59 WvStream *content_source,
bool _create_dirs,
bool _pipeline_test);
73 WvUrlLink(WvStringParm _linkname, WvStringParm _url)
74 : linkname(_linkname), url(_url)
90 WvHTTPHeaderDict headers;
92 WvBufUrlStream() : status(0), headers(10)
94 virtual ~WvBufUrlStream()
98 const char *wstype()
const {
return "WvBufUrlStream"; }
110 WvIPPortAddr remaddr;
113 Target(
const WvIPPortAddr &_remaddr, WvStringParm _username)
114 : remaddr(_remaddr), username(_username) {}
118 bool operator== (
const Target &n2)
const
119 {
return (username == n2.username && remaddr == n2.remaddr); }
122 static int max_requests;
126 WvUrlRequestList urls, waiting_urls;
129 virtual void doneurl() = 0;
130 virtual void request_next() = 0;
133 WvUrlStream(
const WvIPPortAddr &_remaddr, WvStringParm _username,
134 WvStringParm logname)
135 :
WvStreamClone(new WvTCPConn(_remaddr)), target(_remaddr, _username),
136 log(logname, WvLog::Debug)
142 virtual ~WvUrlStream() {};
148 virtual size_t remaining()
154 const char *wstype()
const {
return "WvUrlStream"; }
165 static bool global_enable_pipelining;
166 bool enable_pipelining;
169 int pipeline_test_count;
171 bool sent_url_request;
172 WvIPPortAddrTable &pipeline_incompatible;
173 WvString http_response, pipeline_test_response;
174 WvDynBuf putstream_data;
176 enum { Unknown, Chunked, ContentLength, Infinity,
177 PostHeadInfinity, PostHeadChunked, PostHeadStream,
178 ChuckInfinity, ChuckChunked, ChuckStream } encoding;
179 size_t bytes_remaining;
180 bool in_chunk_trailer, last_was_pipeline_test, in_doneurl;
182 virtual void doneurl();
183 virtual void request_next();
184 void start_pipeline_test(WvUrl *url);
185 WvString request_str(WvUrlRequest *url,
bool keep_alive);
186 void send_request(WvUrlRequest *url);
187 void pipelining_is_broken(
int why);
190 WvHttpStream(
const WvIPPortAddr &_remaddr, WvStringParm _username,
191 bool ssl, WvIPPortAddrTable &_pipeline_incompatible);
192 virtual ~WvHttpStream();
198 virtual size_t remaining()
199 {
return bytes_remaining; }
202 const char *wstype()
const {
return "WvHttpStream"; }
208 bool logged_in, pasv_acked;
211 time_t last_request_time;
214 virtual void doneurl();
215 virtual void request_next();
219 char *get_important_line();
224 WvIPPortAddr *parse_pasv_response(
char *line);
226 WvString parse_for_links(
char *line);
229 void* real_execute(
void*);
232 WvFtpStream(
const WvIPPortAddr &_remaddr, WvStringParm _username,
233 WvStringParm _password);
241 const char *wstype()
const {
return "WvFtpStream"; }
250 WvUrlStreamDict conns;
251 WvUrlRequestList urls;
252 int num_streams_created;
255 WvIPPortAddrTable pipeline_incompatible;
259 virtual ~WvHttpPool();
265 WvBufUrlStream *addurl(WvStringParm _url, WvStringParm _method =
"GET",
266 WvStringParm _headers =
"",
268 bool create_dirs =
false);
279 {
return !urls.count(); }
282 const char *wstype()
const {
return "WvHttpPool"; }
WvBufStream stores data written by write(), and returns it later on in read().
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual void close()
Close this stream.
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
virtual void close()
Close this stream.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
An IP+Port address also includes a port number, with the resulting form www.xxx.yyy....
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
WvStreamClone simply forwards all requests to the "cloned" stream.
WvStreamClone(IWvStream *_cloned=NULL)
Constructs the stream, then calls setclone(_cloned).
WvStream()
Basic constructor for just a do-nothing WvStream.
WvString is an implementation of a simple and efficient printable-string class.
virtual void close()=0
Close this stream.
virtual void execute()=0
The callback() function calls execute(), and then calls the user- specified callback if one is define...
the data structure used by pre_select()/post_select() and internally by select().