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/indexfile.h>
00025 #include <apt-pkg/vendor.h>
00026 #include <apt-pkg/sourcelist.h>
00027 #include <apt-pkg/pkgrecords.h>
00028 #include <apt-pkg/indexrecords.h>
00029 #include <apt-pkg/hashes.h>
00030 #include <apt-pkg/weakptr.h>
00031 
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(string From,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    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    string UsedMirror;
00147 
00156    unsigned int QueueCounter;
00157    
00161    string DestFile;
00162 
00176    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00177 
00197    virtual void Done(string Message,unsigned long Size,string Hash,
00198                      pkgAcquire::MethodConfig *Cnf);
00199 
00209    virtual void Start(string Message,unsigned long Size);
00210 
00219    virtual string Custom600Headers() {return string();};
00220 
00225    virtual string DescURI() = 0;
00230    virtual string ShortDesc() {return DescURI();}
00231 
00233    virtual void Finished() {};
00234    
00240    virtual string HashSum() {return string();};
00241 
00243    pkgAcquire *GetOwner() {return Owner;};
00244 
00246    virtual bool IsTrusted() {return false;};
00247    
00248    // report mirror problems
00256    void ReportMirrorFailure(string FailCode);
00257 
00258 
00270    Item(pkgAcquire *Owner);
00271 
00275    virtual ~Item();
00276 };
00277                                                                         /*}}}*/         /*{{{*/
00279 struct DiffInfo {
00281    string file;
00282 
00284    string sha1;
00285 
00287    unsigned long size;
00288 };
00289                                                                         /*}}}*/
00299 class pkgAcqDiffIndex : public pkgAcquire::Item
00300 {
00301  protected:
00303    bool Debug;
00304 
00306    pkgAcquire::ItemDesc Desc;
00307 
00311    string RealURI;
00312 
00316    HashString ExpectedHash;
00317 
00321    string CurrentPackagesFile;
00322 
00326    string Description;
00327 
00328  public:
00329    // Specialized action members
00330    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00331    virtual void Done(string Message,unsigned long Size,string Md5Hash,
00332                      pkgAcquire::MethodConfig *Cnf);
00333    virtual string DescURI() {return RealURI + "Index";};
00334    virtual string Custom600Headers();
00335 
00346    bool ParseDiffIndex(string IndexDiffFile);
00347    
00348 
00361    pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc,
00362                    string ShortDesc, HashString ExpectedHash);
00363 };
00364                                                                         /*}}}*/
00376 class pkgAcqIndexDiffs : public pkgAcquire::Item
00377 {
00378    private:
00379 
00389    bool QueueNextDiff();
00390 
00402    void Finish(bool allDone=false);
00403 
00404    protected:
00405 
00409    bool Debug;
00410 
00414    pkgAcquire::ItemDesc Desc;
00415 
00419    string RealURI;
00420 
00424    HashString ExpectedHash;
00425 
00427    string Description;
00428 
00437    vector<DiffInfo> available_patches;
00438 
00440    string ServerSha1;
00441 
00443    enum DiffState
00444      {
00446          StateFetchUnkown,
00447 
00449          StateFetchDiff,
00450          
00452          StateUnzipDiff,
00453 
00455          StateApplyDiff
00456    } State;
00457 
00458    public:
00459    
00465    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00466 
00467    virtual void Done(string Message,unsigned long Size,string Md5Hash,
00468                      pkgAcquire::MethodConfig *Cnf);
00469    virtual string DescURI() {return RealURI + "Index";};
00470 
00493    pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc,
00494                     string ShortDesc, HashString ExpectedHash,
00495                     string ServerSha1,
00496                     vector<DiffInfo> diffs=vector<DiffInfo>());
00497 };
00498                                                                         /*}}}*/
00506 class pkgAcqIndex : public pkgAcquire::Item
00507 {
00508    protected:
00509 
00511    bool Decompression;
00512 
00516    bool Erase;
00517 
00521    pkgAcquire::ItemDesc Desc;
00522 
00526    string RealURI;
00527 
00529    HashString ExpectedHash;
00530 
00534    string CompressionExtension;
00535 
00538    std::string GetFinalFilename(std::string const &URI,
00539                                 std::string const &compExt);
00540 
00542    void ReverifyAfterIMS(std::string const &FileName);
00543 
00544    public:
00545    
00546    // Specialized action members
00547    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00548    virtual void Done(string Message,unsigned long Size,string Md5Hash,
00549                      pkgAcquire::MethodConfig *Cnf);
00550    virtual string Custom600Headers();
00551    virtual string DescURI() {return RealURI + CompressionExtension;};
00552    virtual string HashSum() {return ExpectedHash.toStr(); };
00553 
00573    pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
00574                string ShortDesc, HashString ExpectedHash, 
00575                string compressExt="");
00576 };
00577                                                                         /*}}}*/
00585 class pkgAcqIndexTrans : public pkgAcqIndex
00586 {
00587    public:
00588   
00589    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00590    virtual string Custom600Headers();
00591 
00603    pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
00604                     string ShortDesc);
00605 };
00606                                                                         /*}}}*/                         /*{{{*/
00608 struct IndexTarget
00609 {
00611    string URI;
00612 
00614    string Description;
00615 
00617    string ShortDesc;
00618 
00622    string MetaKey;
00623 };
00624                                                                         /*}}}*/
00633 class pkgAcqMetaSig : public pkgAcquire::Item
00634 {
00635    protected:
00637    string LastGoodSig;
00638 
00640    pkgAcquire::ItemDesc Desc;
00641 
00646    string RealURI;
00647 
00649    string MetaIndexURI;
00650 
00654    string MetaIndexURIDesc;
00655 
00659    string MetaIndexShortDesc;
00660 
00662    indexRecords* MetaIndexParser;
00663 
00669    const vector<struct IndexTarget*>* IndexTargets;
00670 
00671    public:
00672    
00673    // Specialized action members
00674    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00675    virtual void Done(string Message,unsigned long Size,string Md5Hash,
00676                      pkgAcquire::MethodConfig *Cnf);
00677    virtual string Custom600Headers();
00678    virtual string DescURI() {return RealURI; };
00679 
00681    pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
00682                  string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
00683                  const vector<struct IndexTarget*>* IndexTargets,
00684                  indexRecords* MetaIndexParser);
00685 };
00686                                                                         /*}}}*/
00697 class pkgAcqMetaIndex : public pkgAcquire::Item
00698 {
00699    protected:
00701    pkgAcquire::ItemDesc Desc;
00702 
00706    string RealURI;
00707 
00713    string SigFile;
00714 
00716    const vector<struct IndexTarget*>* IndexTargets;
00717 
00719    indexRecords* MetaIndexParser;
00720 
00723    bool AuthPass;
00724    // required to deal gracefully with problems caused by incorrect ims hits
00725    bool IMSHit; 
00726 
00732    bool VerifyVendor(string Message);
00733 
00743    void RetrievalDone(string Message);
00744 
00754    void AuthDone(string Message);
00755 
00764    void QueueIndexes(bool verify);
00765    
00766    public:
00767    
00768    // Specialized action members
00769    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00770    virtual void Done(string Message,unsigned long Size, string Hash,
00771                      pkgAcquire::MethodConfig *Cnf);
00772    virtual string Custom600Headers();
00773    virtual string DescURI() {return RealURI; };
00774 
00776    pkgAcqMetaIndex(pkgAcquire *Owner,
00777                    string URI,string URIDesc, string ShortDesc,
00778                    string SigFile,
00779                    const vector<struct IndexTarget*>* IndexTargets,
00780                    indexRecords* MetaIndexParser);
00781 };
00782                                                                         /*}}}*/
00788 class pkgAcqArchive : public pkgAcquire::Item
00789 {
00790    protected:
00792    pkgCache::VerIterator Version;
00793 
00795    pkgAcquire::ItemDesc Desc;
00796 
00800    pkgSourceList *Sources;
00801 
00805    pkgRecords *Recs;
00806 
00808    HashString ExpectedHash;
00809 
00813    string &StoreFilename;
00814 
00816    pkgCache::VerFileIterator Vf;
00817 
00823    unsigned int Retries;
00824 
00828    bool Trusted; 
00829 
00831    bool QueueNext();
00832    
00833    public:
00834    
00835    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00836    virtual void Done(string Message,unsigned long Size,string Hash,
00837                      pkgAcquire::MethodConfig *Cnf);
00838    virtual string DescURI() {return Desc.URI;};
00839    virtual string ShortDesc() {return Desc.ShortDesc;};
00840    virtual void Finished();
00841    virtual string HashSum() {return ExpectedHash.toStr(); };
00842    virtual bool IsTrusted();
00843    
00862    pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
00863                  pkgRecords *Recs,pkgCache::VerIterator const &Version,
00864                  string &StoreFilename);
00865 };
00866                                                                         /*}}}*/
00873 class pkgAcqFile : public pkgAcquire::Item
00874 {
00876    pkgAcquire::ItemDesc Desc;
00877 
00879    HashString ExpectedHash;
00880 
00884    unsigned int Retries;
00885    
00887    bool IsIndexFile;
00888 
00889    public:
00890    
00891    // Specialized action members
00892    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00893    virtual void Done(string Message,unsigned long Size,string CalcHash,
00894                      pkgAcquire::MethodConfig *Cnf);
00895    virtual string DescURI() {return Desc.URI;};
00896    virtual string HashSum() {return ExpectedHash.toStr(); };
00897    virtual string Custom600Headers();
00898 
00930    pkgAcqFile(pkgAcquire *Owner, string URI, string Hash, unsigned long Size,
00931               string Desc, string ShortDesc,
00932               const string &DestDir="", const string &DestFilename="",
00933               bool IsIndexFile=false);
00934 };
00935                                                                         /*}}}*/
00938 #endif