]>
Commit | Line | Data |
---|---|---|
4b5ea8a6 CT |
1 | /* |
2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
55369ae6 AR |
9 | #ifndef SQUID_DOWNLOADER_H |
10 | #define SQUID_DOWNLOADER_H | |
11 | ||
cda7024f | 12 | #include "base/AsyncJob.h" |
cda7024f | 13 | #include "defines.h" |
4b5ea8a6 | 14 | #include "http/forward.h" |
cda7024f CT |
15 | #include "http/StatusCode.h" |
16 | #include "sbuf/SBuf.h" | |
55369ae6 | 17 | |
cda7024f CT |
18 | class ClientHttpRequest; |
19 | class StoreIOBuffer; | |
20 | class clientStreamNode; | |
a175ef71 CT |
21 | class DownloaderContext; |
22 | typedef RefCount<DownloaderContext> DownloaderContextPointer; | |
cda7024f | 23 | |
a175ef71 CT |
24 | /// The Downloader class fetches SBuf-storable things for other Squid |
25 | /// components/transactions using internal requests. For example, it is used | |
26 | /// to fetch missing intermediate certificates when validating origin server | |
27 | /// certificate chains. | |
cda7024f | 28 | class Downloader: virtual public AsyncJob |
55369ae6 AR |
29 | { |
30 | CBDATA_CLASS(Downloader); | |
55369ae6 | 31 | public: |
6cae08c9 | 32 | |
168d2b30 | 33 | /// Callback data to use with Downloader callbacks. |
4cab96c5 | 34 | class CbDialer: public CallDialer { |
55369ae6 AR |
35 | public: |
36 | CbDialer(): status(Http::scNone) {} | |
37 | virtual ~CbDialer() {} | |
4cab96c5 CT |
38 | |
39 | /* CallDialer API */ | |
40 | virtual bool canDial(AsyncCall &call) = 0; | |
41 | virtual void dial(AsyncCall &call) = 0; | |
42 | virtual void print(std::ostream &os) const; | |
43 | ||
55369ae6 AR |
44 | SBuf object; |
45 | Http::StatusCode status; | |
46 | }; | |
47 | ||
cda7024f | 48 | Downloader(SBuf &url, AsyncCall::Pointer &aCallback, unsigned int level = 0); |
55369ae6 | 49 | virtual ~Downloader(); |
6cae08c9 | 50 | |
4b5ea8a6 | 51 | /// delays destruction to protect doCallouts() |
55369ae6 | 52 | void downloadFinished(); |
4e526b93 | 53 | |
168d2b30 | 54 | /// The nested level of Downloader object (downloads inside downloads). |
4e526b93 | 55 | unsigned int nestedLevel() const {return level_;} |
3945c91d | 56 | |
4b5ea8a6 | 57 | void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer); |
55369ae6 | 58 | |
55369ae6 | 59 | protected: |
55369ae6 AR |
60 | |
61 | /* AsyncJob API */ | |
4b5ea8a6 | 62 | virtual bool doneAll() const; |
55369ae6 AR |
63 | virtual void start(); |
64 | ||
65 | private: | |
cda7024f CT |
66 | |
67 | bool buildRequest(); | |
4b5ea8a6 | 68 | void callBack(Http::StatusCode const status); |
6cae08c9 | 69 | |
168d2b30 CT |
70 | /// The maximum allowed object size. |
71 | static const size_t MaxObjectSize = 1*1024*1024; | |
6cae08c9 | 72 | |
168d2b30 | 73 | SBuf url_; ///< the url to download |
4b5ea8a6 CT |
74 | AsyncCall::Pointer callback_; ///< callback to call when download finishes |
75 | SBuf object_; ///< the object body data | |
a175ef71 | 76 | const unsigned int level_; ///< holds the nested downloads level |
cda7024f | 77 | |
a175ef71 CT |
78 | /// Pointer to an object that stores the clientStream required info |
79 | DownloaderContextPointer context_; | |
55369ae6 AR |
80 | }; |
81 | ||
82 | #endif | |
3945c91d | 83 |