- change the internal handling of Extensions in pkgAcqIndex
[ntk/apt.git] / apt-pkg / acquire-item.h
index af0b2d8..92098e3 100644 (file)
@@ -27,6 +27,7 @@
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/indexrecords.h>
 #include <apt-pkg/hashes.h>
+#include <apt-pkg/weakptr.h>
 
 /** \addtogroup acquire
  *  @{
@@ -34,7 +35,7 @@
  *  \file acquire-item.h
  */
 
-/** \brief Represents the process by which a pkgAcquire object should
+/** \brief Represents the process by which a pkgAcquire object should  {{{
  *  retrieve a file or a collection of files.
  *
  *  By convention, Item subclasses should insert themselves into the
@@ -46,7 +47,7 @@
  *
  *  \see pkgAcquire
  */
-class pkgAcquire::Item
+class pkgAcquire::Item : public WeakPointable
 {  
    protected:
    
@@ -111,10 +112,10 @@ class pkgAcquire::Item
    string ErrorText;
 
    /** \brief The size of the object to fetch. */
-   unsigned long FileSize;
+   unsigned long long FileSize;
 
    /** \brief How much of the object was already fetched. */
-   unsigned long PartialSize;
+   unsigned long long PartialSize;
 
    /** \brief If not \b NULL, contains the name of a subprocess that
     *  is operating on this object (for instance, "gzip" or "gpgv").
@@ -273,8 +274,8 @@ class pkgAcquire::Item
     */
    virtual ~Item();
 };
-
-/** \brief Information about an index patch (aka diff). */
+                                                                       /*}}}*/
+/** \brief Information about an index patch (aka diff). */             /*{{{*/
 struct DiffInfo {
    /** The filename of the diff. */
    string file;
@@ -285,8 +286,8 @@ struct DiffInfo {
    /** The size of the diff. */
    unsigned long size;
 };
-
-/** \brief An item that is responsible for fetching an index file of
+                                                                       /*}}}*/
+/** \brief An item that is responsible for fetching an index file of   {{{
  *  package list diffs and starting the package list's download.
  *
  *  This item downloads the Index file and parses it, then enqueues
@@ -360,8 +361,8 @@ class pkgAcqDiffIndex : public pkgAcquire::Item
    pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc,
                   string ShortDesc, HashString ExpectedHash);
 };
-
-/** \brief An item that is responsible for fetching all the patches
+                                                                       /*}}}*/
+/** \brief An item that is responsible for fetching all the patches    {{{
  *  that need to be applied to a given package index file.
  *
  *  After downloading and applying a single patch, this item will
@@ -434,6 +435,10 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item
     *  off the front?
     */
    vector<DiffInfo> available_patches;
+
+   /** Stop applying patches when reaching that sha1 */
+   string ServerSha1;
+
    /** The current status of this patch. */
    enum DiffState
      {
@@ -444,7 +449,7 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item
         StateFetchDiff,
         
         /** \brief The diff is currently being uncompressed. */
-        StateUnzipDiff,
+        StateUnzipDiff, // FIXME: No longer used
 
         /** \brief The diff is currently being applied. */
         StateApplyDiff
@@ -487,10 +492,11 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item
     */
    pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc,
                    string ShortDesc, HashString ExpectedHash,
+                   string ServerSha1,
                    vector<DiffInfo> diffs=vector<DiffInfo>());
 };
-
-/** \brief An acquire item that is responsible for fetching an index
+                                                                       /*}}}*/
+/** \brief An acquire item that is responsible for fetching an index   {{{
  *  file (e.g., Packages or Sources).
  *
  *  \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
@@ -522,8 +528,8 @@ class pkgAcqIndex : public pkgAcquire::Item
    /** \brief The expected hashsum of the decompressed index file. */
    HashString ExpectedHash;
 
-   /** \brief The compression-related file extension that is being
-    *  added to the downloaded file (e.g., ".gz" or ".bz2").
+   /** \brief The compression-related file extensions that are being
+    *  added to the downloaded file one by one if first fails (e.g., "gz bz2").
     */
    string CompressionExtension;
 
@@ -534,7 +540,7 @@ class pkgAcqIndex : public pkgAcquire::Item
    virtual void Done(string Message,unsigned long Size,string Md5Hash,
                     pkgAcquire::MethodConfig *Cnf);
    virtual string Custom600Headers();
-   virtual string DescURI() {return RealURI + CompressionExtension;};
+   virtual string DescURI() {return Desc.URI;};
    virtual string HashSum() {return ExpectedHash.toStr(); };
 
    /** \brief Create a pkgAcqIndex.
@@ -552,14 +558,19 @@ class pkgAcqIndex : public pkgAcquire::Item
     *
     *  \param compressExt The compression-related extension with which
     *  this index file should be downloaded, or "" to autodetect
-    *  (".bz2" is used if bzip2 is installed, ".gz" otherwise).
+    *  Compression types can be set with config Acquire::CompressionTypes,
+    *  default is ".lzma" or ".bz2" (if the needed binaries are present)
+    *  fallback is ".gz" or none.
     */
    pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
               string ShortDesc, HashString ExpectedHash, 
               string compressExt="");
+   pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target,
+                        HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
+   void Init(string const &URI, string const &URIDesc, string const &ShortDesc);
 };
-
-/** \brief An acquire item that is responsible for fetching a
+                                                                       /*}}}*/
+/** \brief An acquire item that is responsible for fetching a          {{{
  *  translated index file.
  *
  *  The only difference from pkgAcqIndex is that transient failures
@@ -571,6 +582,7 @@ class pkgAcqIndexTrans : public pkgAcqIndex
    public:
   
    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
+   virtual string Custom600Headers();
 
    /** \brief Create a pkgAcqIndexTrans.
     *
@@ -582,18 +594,12 @@ class pkgAcqIndexTrans : public pkgAcqIndex
     *  \param URIDesc A "URI-style" description of this index file.
     *
     *  \param ShortDesc A brief description of this index file.
-    *
-    *  \param ExpectedHash The expected hashsum of this index file.
-    *
-    *  \param compressExt The compression-related extension with which
-    *  this index file should be downloaded, or "" to autodetect
-    *  (".bz2" is used if bzip2 is installed, ".gz" otherwise).
     */
    pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
                    string ShortDesc);
 };
-
-/** \brief Information about an index file. */
+                                                                       /*}}}*/
+/** \brief Information about an index file. */                         /*{{{*/
 struct IndexTarget
 {
    /** \brief A URI from which the index file can be downloaded. */
@@ -610,8 +616,8 @@ struct IndexTarget
     */
    string MetaKey;
 };
-
-/** \brief An acquire item that downloads the detached signature
+                                                                       /*}}}*/
+/** \brief An acquire item that downloads the detached signature       {{{
  *  of a meta-index (Release) file, then queues up the release
  *  file itself.
  *
@@ -672,8 +678,8 @@ class pkgAcqMetaSig : public pkgAcquire::Item
                 const vector<struct IndexTarget*>* IndexTargets,
                 indexRecords* MetaIndexParser);
 };
-
-/** \brief An item that is responsible for downloading the meta-index
+                                                                       /*}}}*/
+/** \brief An item that is responsible for downloading the meta-index  {{{
  *  file (i.e., Release) itself and verifying its signature.
  *
  *  Once the download and verification are complete, the downloads of
@@ -768,8 +774,41 @@ class pkgAcqMetaIndex : public pkgAcquire::Item
                   const vector<struct IndexTarget*>* IndexTargets,
                   indexRecords* MetaIndexParser);
 };
+                                                                       /*}}}*/
+/** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
+class pkgAcqMetaClearSig : public pkgAcqMetaIndex
+{
+   /** \brief The URI of the meta-index file for the detached signature */
+   string MetaIndexURI;
+
+   /** \brief A "URI-style" description of the meta-index file */
+   string MetaIndexURIDesc;
+
+   /** \brief A brief description of the meta-index file */
+   string MetaIndexShortDesc;
+
+   /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
+   string MetaSigURI;
 
-/** \brief An item that is responsible for fetching a package file.
+   /** \brief A "URI-style" description of the meta-signature file */
+   string MetaSigURIDesc;
+
+   /** \brief A brief description of the meta-signature file */
+   string MetaSigShortDesc;
+
+public:
+   void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
+
+   /** \brief Create a new pkgAcqMetaClearSig. */
+   pkgAcqMetaClearSig(pkgAcquire *Owner,
+               string const &URI, string const &URIDesc, string const &ShortDesc,
+               string const &MetaIndexURI, string const &MetaIndexURIDesc, string const &MetaIndexShortDesc,
+               string const &MetaSigURI, string const &MetaSigURIDesc, string const &MetaSigShortDesc,
+               const vector<struct IndexTarget*>* IndexTargets,
+               indexRecords* MetaIndexParser);
+};
+                                                                       /*}}}*/
+/** \brief An item that is responsible for fetching a package file.    {{{
  *
  *  If the package file already exists in the cache, nothing will be
  *  done.
@@ -852,8 +891,8 @@ class pkgAcqArchive : public pkgAcquire::Item
                 pkgRecords *Recs,pkgCache::VerIterator const &Version,
                 string &StoreFilename);
 };
-
-/** \brief Retrieve an arbitrary file to the current directory.
+                                                                       /*}}}*/
+/** \brief Retrieve an arbitrary file to the current directory.                {{{
  *
  *  The file is retrieved even if it is accessed via a URL type that
  *  normally is a NOP, such as "file".  If the download fails, the
@@ -872,6 +911,9 @@ class pkgAcqFile : public pkgAcquire::Item
     */
    unsigned int Retries;
    
+   /** \brief Should this file be considered a index file */
+   bool IsIndexFile;
+
    public:
    
    // Specialized action members
@@ -880,6 +922,7 @@ class pkgAcqFile : public pkgAcquire::Item
                     pkgAcquire::MethodConfig *Cnf);
    virtual string DescURI() {return Desc.URI;};
    virtual string HashSum() {return ExpectedHash.toStr(); };
+   virtual string Custom600Headers();
 
    /** \brief Create a new pkgAcqFile object.
     *
@@ -903,6 +946,8 @@ class pkgAcqFile : public pkgAcquire::Item
     *
     *  \param DestFilename The filename+path the file is downloaded to.
     *
+    *  \param IsIndexFile The file is considered a IndexFile and cache-control
+    *                     headers like "cache-control: max-age=0" are send
     *
     * If DestFilename is empty, download to DestDir/<basename> if
     * DestDir is non-empty, $CWD/<basename> otherwise.  If
@@ -912,9 +957,10 @@ class pkgAcqFile : public pkgAcquire::Item
 
    pkgAcqFile(pkgAcquire *Owner, string URI, string Hash, unsigned long Size,
              string Desc, string ShortDesc,
-             const string &DestDir="", const string &DestFilename="");
+             const string &DestDir="", const string &DestFilename="",
+             bool IsIndexFile=false);
 };
-
+                                                                       /*}}}*/
 /** @} */
 
 #endif