]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Downloader.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / Downloader.h
1 /*
2 * Copyright (C) 1996-2018 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 #include "XactionInitiator.h"
18
19 class ClientHttpRequest;
20 class StoreIOBuffer;
21 class clientStreamNode;
22 class DownloaderContext;
23 typedef RefCount<DownloaderContext> DownloaderContextPointer;
24
25 /// The Downloader class fetches SBuf-storable things for other Squid
26 /// components/transactions using internal requests. For example, it is used
27 /// to fetch missing intermediate certificates when validating origin server
28 /// certificate chains.
29 class Downloader: virtual public AsyncJob
30 {
31 CBDATA_CLASS(Downloader);
32 public:
33
34 /// Callback data to use with Downloader callbacks.
35 class CbDialer: public CallDialer {
36 public:
37 CbDialer(): status(Http::scNone) {}
38 virtual ~CbDialer() {}
39
40 /* CallDialer API */
41 virtual bool canDial(AsyncCall &call) = 0;
42 virtual void dial(AsyncCall &call) = 0;
43 virtual void print(std::ostream &os) const;
44
45 SBuf object;
46 Http::StatusCode status;
47 };
48
49 Downloader(SBuf &url, AsyncCall::Pointer &aCallback, const XactionInitiator initiator, unsigned int level = 0);
50 virtual ~Downloader();
51 virtual void swanSong();
52
53 /// delays destruction to protect doCallouts()
54 void downloadFinished();
55
56 /// The nested level of Downloader object (downloads inside downloads).
57 unsigned int nestedLevel() const {return level_;}
58
59 void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer);
60
61 protected:
62
63 /* AsyncJob API */
64 virtual bool doneAll() const;
65 virtual void start();
66
67 private:
68
69 bool buildRequest();
70 void callBack(Http::StatusCode const status);
71
72 /// The maximum allowed object size.
73 static const size_t MaxObjectSize = 1*1024*1024;
74
75 SBuf url_; ///< the url to download
76 AsyncCall::Pointer callback_; ///< callback to call when download finishes
77 SBuf object_; ///< the object body data
78 const unsigned int level_; ///< holds the nested downloads level
79 /// The initiator of the download request.
80 XactionInitiator initiator_;
81
82 /// Pointer to an object that stores the clientStream required info
83 DownloaderContextPointer context_;
84 };
85
86 #endif
87