]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/Downloader.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / Downloader.h
index b11a112a83a8572bfd8f2b82f2d0440185666669..7f8dca42e83c35cd86e4adeb9a75b5d401620051 100644 (file)
@@ -1,89 +1,84 @@
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #ifndef SQUID_DOWNLOADER_H
 #define SQUID_DOWNLOADER_H
 
-#include "base/AsyncCall.h"
 #include "base/AsyncJob.h"
-#include "cbdata.h"
 #include "defines.h"
+#include "http/forward.h"
 #include "http/StatusCode.h"
 #include "sbuf/SBuf.h"
 
 class ClientHttpRequest;
 class StoreIOBuffer;
 class clientStreamNode;
-class HttpReply;
-class Downloader;
-
-class DownloaderContext: public RefCountable
-{
-    CBDATA_CLASS(DownloaderContext);
-
-public:
-    typedef RefCount<DownloaderContext> Pointer;
-
-    DownloaderContext(Downloader *dl, ClientHttpRequest *h):
-        downloader(cbdataReference(dl)),
-        http(cbdataReference(h))
-        {}
-    ~DownloaderContext();
-    void finished();
-    Downloader* downloader;
-    ClientHttpRequest *http;
-    char requestBuffer[HTTP_REQBUF_SZ];
-};
+class DownloaderContext;
+typedef RefCount<DownloaderContext> DownloaderContextPointer;
 
+/// The Downloader class fetches SBuf-storable things for other Squid
+/// components/transactions using internal requests. For example, it is used
+/// to fetch missing intermediate certificates when validating origin server
+/// certificate chains.
 class Downloader: virtual public AsyncJob
 {
     CBDATA_CLASS(Downloader);
 public:
 
     /// Callback data to use with Downloader callbacks.
-    class CbDialer {
+    class CbDialer: public CallDialer {
     public:
         CbDialer(): status(Http::scNone) {}
         virtual ~CbDialer() {}
+
+        /* CallDialer API */
+        virtual bool canDial(AsyncCall &call) = 0;
+        virtual void dial(AsyncCall &call) = 0;
+        virtual void print(std::ostream &os) const;
+
         SBuf object;
         Http::StatusCode status;
     };
 
     Downloader(SBuf &url, AsyncCall::Pointer &aCallback, unsigned int level = 0);
     virtual ~Downloader();
+    virtual void swanSong();
 
-    /// Fake call used internally by Downloader.
+    /// delays destruction to protect doCallouts()
     void downloadFinished();
 
     /// The nested level of Downloader object (downloads inside downloads).
     unsigned int nestedLevel() const {return level_;}
-    
-    /* AsyncJob API */
-    virtual bool doneAll() const;
 
-    DownloaderContext::Pointer const &context() {return context_;};
-    void handleReply(clientStreamNode * node, ClientHttpRequest *http, HttpReply *header, StoreIOBuffer receivedData);
+    void handleReply(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer);
+
 protected:
 
     /* AsyncJob API */
+    virtual bool doneAll() const;
     virtual void start();
-    virtual void prepUserConnection() {};
 
 private:
 
     bool buildRequest();
-
-    /// Schedules for execution the "callback" with parameters the status
-    /// and object.
-    void callBack();
+    void callBack(Http::StatusCode const status);
 
     /// The maximum allowed object size.
     static const size_t MaxObjectSize = 1*1024*1024;
 
     SBuf url_; ///< the url to download
-    AsyncCall::Pointer callback; ///< callback to call when download finishes
-    Http::StatusCode status; ///< the download status code
-    SBuf object; ///< the object body data
-    unsigned int level_; ///< holds the nested downloads level
+    AsyncCall::Pointer callback_; ///< callback to call when download finishes
+    SBuf object_; ///< the object body data
+    const unsigned int level_; ///< holds the nested downloads level
 
-    DownloaderContext::Pointer context_;
+    /// Pointer to an object that stores the clientStream required info
+    DownloaderContextPointer context_;
 };
 
 #endif
+