]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Downloader.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / Downloader.h
1 /*
2 * Copyright (C) 1996-2017 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
9 #ifndef SQUID_DOWNLOADER_H
10 #define SQUID_DOWNLOADER_H
11
12 #include "base/AsyncJob.h"
13 #include "defines.h"
14 #include "http/forward.h"
15 #include "http/StatusCode.h"
16 #include "sbuf/SBuf.h"
17
18 class ClientHttpRequest;
19 class StoreIOBuffer;
20 class clientStreamNode;
21 class DownloaderContext;
22 typedef RefCount<DownloaderContext> DownloaderContextPointer;
23
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.
28 class Downloader: virtual public AsyncJob
29 {
30 CBDATA_CLASS(Downloader);
31 public:
32
33 /// Callback data to use with Downloader callbacks.
34 class CbDialer: public CallDialer {
35 public:
36 CbDialer(): status(Http::scNone) {}
37 virtual ~CbDialer() {}
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
44 SBuf object;
45 Http::StatusCode status;
46 };
47
48 Downloader(SBuf &url, AsyncCall::Pointer &aCallback, unsigned int level = 0);
49 virtual ~Downloader();
50 virtual void swanSong();
51
52 /// delays destruction to protect doCallouts()
53 void downloadFinished();
54
55 /// The nested level of Downloader object (downloads inside downloads).
56 unsigned int nestedLevel() const {return level_;}
57
58 void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer);
59
60 protected:
61
62 /* AsyncJob API */
63 virtual bool doneAll() const;
64 virtual void start();
65
66 private:
67
68 bool buildRequest();
69 void callBack(Http::StatusCode const status);
70
71 /// The maximum allowed object size.
72 static const size_t MaxObjectSize = 1*1024*1024;
73
74 SBuf url_; ///< the url to download
75 AsyncCall::Pointer callback_; ///< callback to call when download finishes
76 SBuf object_; ///< the object body data
77 const unsigned int level_; ///< holds the nested downloads level
78
79 /// Pointer to an object that stores the clientStream required info
80 DownloaderContextPointer context_;
81 };
82
83 #endif
84