]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Downloader.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / Downloader.h
CommitLineData
4b5ea8a6 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4b5ea8a6
CT
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"
5ceaee75 17#include "XactionInitiator.h"
55369ae6 18
cda7024f
CT
19class ClientHttpRequest;
20class StoreIOBuffer;
21class clientStreamNode;
a175ef71
CT
22class DownloaderContext;
23typedef RefCount<DownloaderContext> DownloaderContextPointer;
cda7024f 24
a175ef71
CT
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.
cda7024f 29class Downloader: virtual public AsyncJob
55369ae6
AR
30{
31 CBDATA_CLASS(Downloader);
55369ae6 32public:
6cae08c9 33
168d2b30 34 /// Callback data to use with Downloader callbacks.
4cab96c5 35 class CbDialer: public CallDialer {
55369ae6
AR
36 public:
37 CbDialer(): status(Http::scNone) {}
38 virtual ~CbDialer() {}
4cab96c5
CT
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
55369ae6
AR
45 SBuf object;
46 Http::StatusCode status;
47 };
48
5ceaee75 49 Downloader(SBuf &url, AsyncCall::Pointer &aCallback, const XactionInitiator initiator, unsigned int level = 0);
55369ae6 50 virtual ~Downloader();
0860d5b6 51 virtual void swanSong();
6cae08c9 52
4b5ea8a6 53 /// delays destruction to protect doCallouts()
55369ae6 54 void downloadFinished();
4e526b93 55
168d2b30 56 /// The nested level of Downloader object (downloads inside downloads).
4e526b93 57 unsigned int nestedLevel() const {return level_;}
3945c91d 58
4b5ea8a6 59 void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer);
55369ae6 60
55369ae6 61protected:
55369ae6
AR
62
63 /* AsyncJob API */
4b5ea8a6 64 virtual bool doneAll() const;
55369ae6
AR
65 virtual void start();
66
67private:
cda7024f
CT
68
69 bool buildRequest();
4b5ea8a6 70 void callBack(Http::StatusCode const status);
6cae08c9 71
168d2b30
CT
72 /// The maximum allowed object size.
73 static const size_t MaxObjectSize = 1*1024*1024;
6cae08c9 74
168d2b30 75 SBuf url_; ///< the url to download
4b5ea8a6
CT
76 AsyncCall::Pointer callback_; ///< callback to call when download finishes
77 SBuf object_; ///< the object body data
a175ef71 78 const unsigned int level_; ///< holds the nested downloads level
5ceaee75
CT
79 /// The initiator of the download request.
80 XactionInitiator initiator_;
cda7024f 81
a175ef71
CT
82 /// Pointer to an object that stores the clientStream required info
83 DownloaderContextPointer context_;
55369ae6
AR
84};
85
86#endif
3945c91d 87