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 
00536    public:
00537    
00538    // Specialized action members
00539    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00540    virtual void Done(string Message,unsigned long Size,string Md5Hash,
00541                      pkgAcquire::MethodConfig *Cnf);
00542    virtual string Custom600Headers();
00543    virtual string DescURI() {return RealURI + CompressionExtension;};
00544    virtual string HashSum() {return ExpectedHash.toStr(); };
00545 
00565    pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
00566                string ShortDesc, HashString ExpectedHash, 
00567                string compressExt="");
00568 };
00569                                                                         /*}}}*/
00577 class pkgAcqIndexTrans : public pkgAcqIndex
00578 {
00579    public:
00580   
00581    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00582    virtual string Custom600Headers();
00583 
00595    pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
00596                     string ShortDesc);
00597 };
00598                                                                         /*}}}*/                         /*{{{*/
00600 struct IndexTarget
00601 {
00603    string URI;
00604 
00606    string Description;
00607 
00609    string ShortDesc;
00610 
00614    string MetaKey;
00615 };
00616                                                                         /*}}}*/
00625 class pkgAcqMetaSig : public pkgAcquire::Item
00626 {
00627    protected:
00629    string LastGoodSig;
00630 
00632    pkgAcquire::ItemDesc Desc;
00633 
00638    string RealURI;
00639 
00641    string MetaIndexURI;
00642 
00646    string MetaIndexURIDesc;
00647 
00651    string MetaIndexShortDesc;
00652 
00654    indexRecords* MetaIndexParser;
00655 
00661    const vector<struct IndexTarget*>* IndexTargets;
00662 
00663    public:
00664    
00665    // Specialized action members
00666    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00667    virtual void Done(string Message,unsigned long Size,string Md5Hash,
00668                      pkgAcquire::MethodConfig *Cnf);
00669    virtual string Custom600Headers();
00670    virtual string DescURI() {return RealURI; };
00671 
00673    pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
00674                  string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
00675                  const vector<struct IndexTarget*>* IndexTargets,
00676                  indexRecords* MetaIndexParser);
00677 };
00678                                                                         /*}}}*/
00689 class pkgAcqMetaIndex : public pkgAcquire::Item
00690 {
00691    protected:
00693    pkgAcquire::ItemDesc Desc;
00694 
00698    string RealURI;
00699 
00705    string SigFile;
00706 
00708    const vector<struct IndexTarget*>* IndexTargets;
00709 
00711    indexRecords* MetaIndexParser;
00712 
00715    bool AuthPass;
00716    // required to deal gracefully with problems caused by incorrect ims hits
00717    bool IMSHit; 
00718 
00724    bool VerifyVendor(string Message);
00725 
00735    void RetrievalDone(string Message);
00736 
00746    void AuthDone(string Message);
00747 
00756    void QueueIndexes(bool verify);
00757    
00758    public:
00759    
00760    // Specialized action members
00761    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00762    virtual void Done(string Message,unsigned long Size, string Hash,
00763                      pkgAcquire::MethodConfig *Cnf);
00764    virtual string Custom600Headers();
00765    virtual string DescURI() {return RealURI; };
00766 
00768    pkgAcqMetaIndex(pkgAcquire *Owner,
00769                    string URI,string URIDesc, string ShortDesc,
00770                    string SigFile,
00771                    const vector<struct IndexTarget*>* IndexTargets,
00772                    indexRecords* MetaIndexParser);
00773 };
00774                                                                         /*}}}*/
00780 class pkgAcqArchive : public pkgAcquire::Item
00781 {
00782    protected:
00784    pkgCache::VerIterator Version;
00785 
00787    pkgAcquire::ItemDesc Desc;
00788 
00792    pkgSourceList *Sources;
00793 
00797    pkgRecords *Recs;
00798 
00800    HashString ExpectedHash;
00801 
00805    string &StoreFilename;
00806 
00808    pkgCache::VerFileIterator Vf;
00809 
00815    unsigned int Retries;
00816 
00820    bool Trusted; 
00821 
00823    bool QueueNext();
00824    
00825    public:
00826    
00827    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00828    virtual void Done(string Message,unsigned long Size,string Hash,
00829                      pkgAcquire::MethodConfig *Cnf);
00830    virtual string DescURI() {return Desc.URI;};
00831    virtual string ShortDesc() {return Desc.ShortDesc;};
00832    virtual void Finished();
00833    virtual string HashSum() {return ExpectedHash.toStr(); };
00834    virtual bool IsTrusted();
00835    
00854    pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
00855                  pkgRecords *Recs,pkgCache::VerIterator const &Version,
00856                  string &StoreFilename);
00857 };
00858                                                                         /*}}}*/
00865 class pkgAcqFile : public pkgAcquire::Item
00866 {
00868    pkgAcquire::ItemDesc Desc;
00869 
00871    HashString ExpectedHash;
00872 
00876    unsigned int Retries;
00877    
00879    bool IsIndexFile;
00880 
00881    public:
00882    
00883    // Specialized action members
00884    virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
00885    virtual void Done(string Message,unsigned long Size,string CalcHash,
00886                      pkgAcquire::MethodConfig *Cnf);
00887    virtual string DescURI() {return Desc.URI;};
00888    virtual string HashSum() {return ExpectedHash.toStr(); };
00889    virtual string Custom600Headers();
00890 
00922    pkgAcqFile(pkgAcquire *Owner, string URI, string Hash, unsigned long Size,
00923               string Desc, string ShortDesc,
00924               const string &DestDir="", const string &DestFilename="",
00925               bool IsIndexFile=false);
00926 };
00927                                                                         /*}}}*/
00930 #endif