apt @VERSION@
acquire-item.h
Go to the documentation of this file.
00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
00004 /* ######################################################################
00005 
00006    Acquire Item - Item to acquire
00007 
00008    When an item is instantiated it will add it self to the local list in
00009    the Owner Acquire class. Derived classes will then call QueueURI to 
00010    register all the URI's they wish to fetch at the initial moment.   
00011    
00012    Three item classes are provided to provide functionality for
00013    downloading of Index, Translation and Packages files.
00014    
00015    A Archive class is provided for downloading .deb files. It does Hash
00016    checking and source location as well as a retry algorithm.
00017    
00018    ##################################################################### */
00019                                                                         /*}}}*/
00020 #ifndef PKGLIB_ACQUIRE_ITEM_H
00021 #define PKGLIB_ACQUIRE_ITEM_H
00022 
00023 #include <apt-pkg/acquire.h>
00024 #include <apt-pkg/hashes.h>
00025 #include <apt-pkg/weakptr.h>
00026 #include <apt-pkg/pkgcache.h>
00027 
00034 class indexRecords;
00035 class pkgRecords;
00036 class pkgSourceList;
00037 
00050 class pkgAcquire::Item : public WeakPointable
00051 {  
00052    protected:
00053    
00055    pkgAcquire *Owner;
00056 
00062    inline void QueueURI(ItemDesc &Item)
00063                  {Owner->Enqueue(Item);};
00064 
00066    inline void Dequeue() {Owner->Dequeue(this);};
00067    
00077    void Rename(std::string From,std::string To);
00078    
00079    public:
00080 
00082    enum ItemState
00083      {
00085        StatIdle,
00086 
00088        StatFetching,
00089 
00091        StatDone,
00092 
00096        StatError,
00097 
00101        StatAuthError,
00102 
00106        StatTransientNetworkError
00107      } Status;
00108 
00112    std::string ErrorText;
00113 
00115    unsigned long long FileSize;
00116 
00118    unsigned long long PartialSize;
00119 
00123    const char *Mode;
00124 
00132    unsigned long ID;
00133 
00138    bool Complete;
00139 
00145    bool Local;
00146    std::string UsedMirror;
00147 
00156    unsigned int QueueCounter;
00157    
00161    std::string DestFile;
00162 
00176    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00177 
00197    virtual void Done(std::string Message,unsigned long long Size,std::string Hash,
00198                      pkgAcquire::MethodConfig *Cnf);
00199 
00209    virtual void Start(std::string Message,unsigned long long Size);
00210 
00219    virtual std::string Custom600Headers() {return std::string();};
00220 
00225    virtual std::string DescURI() = 0;
00230    virtual std::string ShortDesc() {return DescURI();}
00231 
00233    virtual void Finished() {};
00234    
00240    virtual std::string HashSum() {return std::string();};
00241 
00243    pkgAcquire *GetOwner() {return Owner;};
00244 
00246    virtual bool IsTrusted() {return false;};
00247    
00248    // report mirror problems
00256    void ReportMirrorFailure(std::string FailCode);
00257 
00258 
00270    Item(pkgAcquire *Owner);
00271 
00275    virtual ~Item();
00276 };
00277                                                                         /*}}}*/         /*{{{*/
00279 struct DiffInfo {
00281    std::string file;
00282 
00284    std::string sha1;
00285 
00287    unsigned long size;
00288 };
00289                                                                         /*}}}*/
00296 class pkgAcqSubIndex : public pkgAcquire::Item
00297 {
00298  protected:
00300    bool Debug;
00301 
00303    pkgAcquire::ItemDesc Desc;
00304 
00307    HashString ExpectedHash;
00308 
00309  public:
00310    // Specialized action members
00311    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00312    virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
00313                      pkgAcquire::MethodConfig *Cnf);
00314    virtual std::string DescURI() {return Desc.URI;};
00315    virtual std::string Custom600Headers();
00316    virtual bool ParseIndex(std::string const &IndexFile);
00317 
00330    pkgAcqSubIndex(pkgAcquire *Owner, std::string const &URI,std::string const &URIDesc,
00331                    std::string const &ShortDesc, HashString const &ExpectedHash);
00332 };
00333                                                                         /*}}}*/
00343 class pkgAcqDiffIndex : public pkgAcquire::Item
00344 {
00345  protected:
00347    bool Debug;
00348 
00350    pkgAcquire::ItemDesc Desc;
00351 
00355    std::string RealURI;
00356 
00360    HashString ExpectedHash;
00361 
00365    std::string CurrentPackagesFile;
00366 
00370    std::string Description;
00371 
00372  public:
00373    // Specialized action members
00374    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00375    virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
00376                      pkgAcquire::MethodConfig *Cnf);
00377    virtual std::string DescURI() {return RealURI + "Index";};
00378    virtual std::string Custom600Headers();
00379 
00390    bool ParseDiffIndex(std::string IndexDiffFile);
00391    
00392 
00405    pkgAcqDiffIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
00406                    std::string ShortDesc, HashString ExpectedHash);
00407 };
00408                                                                         /*}}}*/
00420 class pkgAcqIndexDiffs : public pkgAcquire::Item
00421 {
00422    private:
00423 
00433    bool QueueNextDiff();
00434 
00446    void Finish(bool allDone=false);
00447 
00448    protected:
00449 
00453    bool Debug;
00454 
00458    pkgAcquire::ItemDesc Desc;
00459 
00463    std::string RealURI;
00464 
00468    HashString ExpectedHash;
00469 
00471    std::string Description;
00472 
00481    std::vector<DiffInfo> available_patches;
00482 
00484    std::string ServerSha1;
00485 
00487    enum DiffState
00488      {
00490          StateFetchUnkown,
00491 
00493          StateFetchDiff,
00494          
00496          StateUnzipDiff, // FIXME: No longer used
00497 
00499          StateApplyDiff
00500    } State;
00501 
00502    public:
00503    
00509    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00510 
00511    virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
00512                      pkgAcquire::MethodConfig *Cnf);
00513    virtual std::string DescURI() {return RealURI + "Index";};
00514 
00537    pkgAcqIndexDiffs(pkgAcquire *Owner,std::string URI,std::string URIDesc,
00538                     std::string ShortDesc, HashString ExpectedHash,
00539                     std::string ServerSha1,
00540                     std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
00541 };
00542                                                                         /*}}}*/
00550 class pkgAcqIndex : public pkgAcquire::Item
00551 {
00552    protected:
00553 
00555    bool Decompression;
00556 
00560    bool Erase;
00561 
00567    // FIXME: instead of a bool it should use a verify string that will
00568    //        then be used in the pkgAcqIndex::Done method to ensure that
00569    //        the downloaded file contains the expected tag
00570    bool Verify;
00571 
00575    pkgAcquire::ItemDesc Desc;
00576 
00580    std::string RealURI;
00581 
00583    HashString ExpectedHash;
00584 
00588    std::string CompressionExtension;
00589 
00590    public:
00591    
00592    // Specialized action members
00593    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00594    virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
00595                      pkgAcquire::MethodConfig *Cnf);
00596    virtual std::string Custom600Headers();
00597    virtual std::string DescURI() {return Desc.URI;};
00598    virtual std::string HashSum() {return ExpectedHash.toStr(); };
00599 
00619    pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
00620                std::string ShortDesc, HashString ExpectedHash, 
00621                std::string compressExt="");
00622    pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target,
00623                          HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
00624    void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc);
00625 };
00626                                                                         /*}}}*/
00634 class pkgAcqIndexTrans : public pkgAcqIndex
00635 {
00636    public:
00637   
00638    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00639    virtual std::string Custom600Headers();
00640 
00652    pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
00653                     std::string ShortDesc);
00654    pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target,
00655                     HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
00656 };
00657                                                                         /*}}}*/                         /*{{{*/
00659 class IndexTarget
00660 {
00661  public:
00663    std::string URI;
00664 
00666    std::string Description;
00667 
00669    std::string ShortDesc;
00670 
00674    std::string MetaKey;
00675 
00676    virtual bool IsOptional() const {
00677       return false;
00678    }
00679    virtual bool IsSubIndex() const {
00680       return false;
00681    }
00682 };
00683                                                                         /*}}}*/                 /*{{{*/
00685 class OptionalIndexTarget : public IndexTarget
00686 {
00687    virtual bool IsOptional() const {
00688       return true;
00689    }
00690 };
00691                                                                         /*}}}*/                 /*{{{*/
00693 class SubIndexTarget : public IndexTarget
00694 {
00695    virtual bool IsSubIndex() const {
00696       return true;
00697    }
00698 };
00699                                                                         /*}}}*/                 /*{{{*/
00701 class OptionalSubIndexTarget : public OptionalIndexTarget
00702 {
00703    virtual bool IsSubIndex() const {
00704       return true;
00705    }
00706 };
00707                                                                         /*}}}*/
00708 
00717 class pkgAcqMetaSig : public pkgAcquire::Item
00718 {
00719    protected:
00721    std::string LastGoodSig;
00722 
00724    pkgAcquire::ItemDesc Desc;
00725 
00730    std::string RealURI;
00731 
00733    std::string MetaIndexURI;
00734 
00738    std::string MetaIndexURIDesc;
00739 
00743    std::string MetaIndexShortDesc;
00744 
00746    indexRecords* MetaIndexParser;
00747 
00753    const std::vector<struct IndexTarget*>* IndexTargets;
00754 
00755    public:
00756    
00757    // Specialized action members
00758    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00759    virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
00760                      pkgAcquire::MethodConfig *Cnf);
00761    virtual std::string Custom600Headers();
00762    virtual std::string DescURI() {return RealURI; };
00763 
00765    pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc,
00766                  std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc,
00767                  const std::vector<struct IndexTarget*>* IndexTargets,
00768                  indexRecords* MetaIndexParser);
00769 };
00770                                                                         /*}}}*/
00781 class pkgAcqMetaIndex : public pkgAcquire::Item
00782 {
00783    protected:
00785    pkgAcquire::ItemDesc Desc;
00786 
00790    std::string RealURI;
00791 
00797    std::string SigFile;
00798 
00800    const std::vector<struct IndexTarget*>* IndexTargets;
00801 
00803    indexRecords* MetaIndexParser;
00804 
00807    bool AuthPass;
00808    // required to deal gracefully with problems caused by incorrect ims hits
00809    bool IMSHit; 
00810 
00816    bool VerifyVendor(std::string Message);
00817 
00827    void RetrievalDone(std::string Message);
00828 
00838    void AuthDone(std::string Message);
00839 
00848    void QueueIndexes(bool verify);
00849    
00850    public:
00851    
00852    // Specialized action members
00853    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00854    virtual void Done(std::string Message,unsigned long long Size, std::string Hash,
00855                      pkgAcquire::MethodConfig *Cnf);
00856    virtual std::string Custom600Headers();
00857    virtual std::string DescURI() {return RealURI; };
00858 
00860    pkgAcqMetaIndex(pkgAcquire *Owner,
00861                    std::string URI,std::string URIDesc, std::string ShortDesc,
00862                    std::string SigFile,
00863                    const std::vector<struct IndexTarget*>* IndexTargets,
00864                    indexRecords* MetaIndexParser);
00865 };
00866                                                                         /*}}}*/
00868 class pkgAcqMetaClearSig : public pkgAcqMetaIndex
00869 {
00871    std::string MetaIndexURI;
00872 
00874    std::string MetaIndexURIDesc;
00875 
00877    std::string MetaIndexShortDesc;
00878 
00880    std::string MetaSigURI;
00881 
00883    std::string MetaSigURIDesc;
00884 
00886    std::string MetaSigShortDesc;
00887 
00888 public:
00889    void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00890    virtual std::string Custom600Headers();
00891 
00893    pkgAcqMetaClearSig(pkgAcquire *Owner,
00894                 std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
00895                 std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
00896                 std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
00897                 const std::vector<struct IndexTarget*>* IndexTargets,
00898                 indexRecords* MetaIndexParser);
00899 };
00900                                                                         /*}}}*/
00906 class pkgAcqArchive : public pkgAcquire::Item
00907 {
00908    protected:
00910    pkgCache::VerIterator Version;
00911 
00913    pkgAcquire::ItemDesc Desc;
00914 
00918    pkgSourceList *Sources;
00919 
00923    pkgRecords *Recs;
00924 
00926    HashString ExpectedHash;
00927 
00931    std::string &StoreFilename;
00932 
00934    pkgCache::VerFileIterator Vf;
00935 
00941    unsigned int Retries;
00942 
00946    bool Trusted; 
00947 
00949    bool QueueNext();
00950    
00951    public:
00952    
00953    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
00954    virtual void Done(std::string Message,unsigned long long Size,std::string Hash,
00955                      pkgAcquire::MethodConfig *Cnf);
00956    virtual std::string DescURI() {return Desc.URI;};
00957    virtual std::string ShortDesc() {return Desc.ShortDesc;};
00958    virtual void Finished();
00959    virtual std::string HashSum() {return ExpectedHash.toStr(); };
00960    virtual bool IsTrusted();
00961    
00980    pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
00981                  pkgRecords *Recs,pkgCache::VerIterator const &Version,
00982                  std::string &StoreFilename);
00983 };
00984                                                                         /*}}}*/
00991 class pkgAcqFile : public pkgAcquire::Item
00992 {
00994    pkgAcquire::ItemDesc Desc;
00995 
00997    HashString ExpectedHash;
00998 
01002    unsigned int Retries;
01003    
01005    bool IsIndexFile;
01006 
01007    public:
01008    
01009    // Specialized action members
01010    virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
01011    virtual void Done(std::string Message,unsigned long long Size,std::string CalcHash,
01012                      pkgAcquire::MethodConfig *Cnf);
01013    virtual std::string DescURI() {return Desc.URI;};
01014    virtual std::string HashSum() {return ExpectedHash.toStr(); };
01015    virtual std::string Custom600Headers();
01016 
01048    pkgAcqFile(pkgAcquire *Owner, std::string URI, std::string Hash, unsigned long long Size,
01049               std::string Desc, std::string ShortDesc,
01050               const std::string &DestDir="", const std::string &DestFilename="",
01051               bool IsIndexFile=false);
01052 };
01053                                                                         /*}}}*/
01056 #endif