apt
@VERSION@
|
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 00028 #ifndef APT_8_CLEANER_HEADERS 00029 #include <apt-pkg/indexfile.h> 00030 #include <apt-pkg/vendor.h> 00031 #include <apt-pkg/sourcelist.h> 00032 #include <apt-pkg/pkgrecords.h> 00033 #include <apt-pkg/indexrecords.h> 00034 #endif 00035 00042 class indexRecords; 00043 class pkgRecords; 00044 class pkgSourceList; 00045 00058 class pkgAcquire::Item : public WeakPointable 00059 { 00060 protected: 00061 00063 pkgAcquire *Owner; 00064 00070 inline void QueueURI(ItemDesc &Item) 00071 {Owner->Enqueue(Item);}; 00072 00074 inline void Dequeue() {Owner->Dequeue(this);}; 00075 00085 void Rename(std::string From,std::string To); 00086 00087 public: 00088 00090 enum ItemState 00091 { 00093 StatIdle, 00094 00096 StatFetching, 00097 00099 StatDone, 00100 00104 StatError, 00105 00109 StatAuthError, 00110 00114 StatTransientNetworkError 00115 } Status; 00116 00120 std::string ErrorText; 00121 00123 unsigned long long FileSize; 00124 00126 unsigned long long PartialSize; 00127 00131 const char *Mode; 00132 00140 unsigned long ID; 00141 00146 bool Complete; 00147 00153 bool Local; 00154 std::string UsedMirror; 00155 00164 unsigned int QueueCounter; 00165 00169 std::string DestFile; 00170 00184 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00185 00205 virtual void Done(std::string Message,unsigned long long Size,std::string Hash, 00206 pkgAcquire::MethodConfig *Cnf); 00207 00217 virtual void Start(std::string Message,unsigned long long Size); 00218 00227 virtual std::string Custom600Headers() {return std::string();}; 00228 00233 virtual std::string DescURI() = 0; 00238 virtual std::string ShortDesc() {return DescURI();} 00239 00241 virtual void Finished() {}; 00242 00248 virtual std::string HashSum() {return std::string();}; 00249 00251 pkgAcquire *GetOwner() {return Owner;}; 00252 00254 virtual bool IsTrusted() {return false;}; 00255 00256 // report mirror problems 00264 void ReportMirrorFailure(std::string FailCode); 00265 00266 00278 Item(pkgAcquire *Owner); 00279 00283 virtual ~Item(); 00284 }; 00285 /*}}}*/ /*{{{*/ 00287 struct DiffInfo { 00289 std::string file; 00290 00292 std::string sha1; 00293 00295 unsigned long size; 00296 }; 00297 /*}}}*/ 00304 class pkgAcqSubIndex : public pkgAcquire::Item 00305 { 00306 protected: 00308 bool Debug; 00309 00311 pkgAcquire::ItemDesc Desc; 00312 00315 HashString ExpectedHash; 00316 00317 public: 00318 // Specialized action members 00319 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00320 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00321 pkgAcquire::MethodConfig *Cnf); 00322 virtual std::string DescURI() {return Desc.URI;}; 00323 virtual std::string Custom600Headers(); 00324 virtual bool ParseIndex(std::string const &IndexFile); 00325 00338 pkgAcqSubIndex(pkgAcquire *Owner, std::string const &URI,std::string const &URIDesc, 00339 std::string const &ShortDesc, HashString const &ExpectedHash); 00340 }; 00341 /*}}}*/ 00351 class pkgAcqDiffIndex : public pkgAcquire::Item 00352 { 00353 protected: 00355 bool Debug; 00356 00358 pkgAcquire::ItemDesc Desc; 00359 00363 std::string RealURI; 00364 00368 HashString ExpectedHash; 00369 00373 std::string CurrentPackagesFile; 00374 00378 std::string Description; 00379 00380 public: 00381 // Specialized action members 00382 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00383 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00384 pkgAcquire::MethodConfig *Cnf); 00385 virtual std::string DescURI() {return RealURI + "Index";}; 00386 virtual std::string Custom600Headers(); 00387 00398 bool ParseDiffIndex(std::string IndexDiffFile); 00399 00400 00413 pkgAcqDiffIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc, 00414 std::string ShortDesc, HashString ExpectedHash); 00415 }; 00416 /*}}}*/ 00428 class pkgAcqIndexDiffs : public pkgAcquire::Item 00429 { 00430 private: 00431 00441 bool QueueNextDiff(); 00442 00454 void Finish(bool allDone=false); 00455 00456 protected: 00457 00461 bool Debug; 00462 00466 pkgAcquire::ItemDesc Desc; 00467 00471 std::string RealURI; 00472 00476 HashString ExpectedHash; 00477 00479 std::string Description; 00480 00489 std::vector<DiffInfo> available_patches; 00490 00492 std::string ServerSha1; 00493 00495 enum DiffState 00496 { 00498 StateFetchUnkown, 00499 00501 StateFetchDiff, 00502 00504 StateUnzipDiff, // FIXME: No longer used 00505 00507 StateApplyDiff 00508 } State; 00509 00510 public: 00511 00517 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00518 00519 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00520 pkgAcquire::MethodConfig *Cnf); 00521 virtual std::string DescURI() {return RealURI + "Index";}; 00522 00545 pkgAcqIndexDiffs(pkgAcquire *Owner,std::string URI,std::string URIDesc, 00546 std::string ShortDesc, HashString ExpectedHash, 00547 std::string ServerSha1, 00548 std::vector<DiffInfo> diffs=std::vector<DiffInfo>()); 00549 }; 00550 /*}}}*/ 00558 class pkgAcqIndex : public pkgAcquire::Item 00559 { 00560 protected: 00561 00563 bool Decompression; 00564 00568 bool Erase; 00569 00575 // FIXME: instead of a bool it should use a verify string that will 00576 // then be used in the pkgAcqIndex::Done method to ensure that 00577 // the downloaded file contains the expected tag 00578 bool Verify; 00579 00583 pkgAcquire::ItemDesc Desc; 00584 00588 std::string RealURI; 00589 00591 HashString ExpectedHash; 00592 00596 std::string CompressionExtension; 00597 00598 public: 00599 00600 // Specialized action members 00601 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00602 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00603 pkgAcquire::MethodConfig *Cnf); 00604 virtual std::string Custom600Headers(); 00605 virtual std::string DescURI() {return Desc.URI;}; 00606 virtual std::string HashSum() {return ExpectedHash.toStr(); }; 00607 00627 pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc, 00628 std::string ShortDesc, HashString ExpectedHash, 00629 std::string compressExt=""); 00630 pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target, 00631 HashString const &ExpectedHash, indexRecords const *MetaIndexParser); 00632 void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc); 00633 }; 00634 /*}}}*/ 00642 class pkgAcqIndexTrans : public pkgAcqIndex 00643 { 00644 public: 00645 00646 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00647 virtual std::string Custom600Headers(); 00648 00660 pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc, 00661 std::string ShortDesc); 00662 pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target, 00663 HashString const &ExpectedHash, indexRecords const *MetaIndexParser); 00664 }; 00665 /*}}}*/ /*{{{*/ 00667 class IndexTarget 00668 { 00669 public: 00671 std::string URI; 00672 00674 std::string Description; 00675 00677 std::string ShortDesc; 00678 00682 std::string MetaKey; 00683 00684 virtual bool IsOptional() const { 00685 return false; 00686 } 00687 virtual bool IsSubIndex() const { 00688 return false; 00689 } 00690 }; 00691 /*}}}*/ /*{{{*/ 00693 class OptionalIndexTarget : public IndexTarget 00694 { 00695 virtual bool IsOptional() const { 00696 return true; 00697 } 00698 }; 00699 /*}}}*/ /*{{{*/ 00701 class SubIndexTarget : public IndexTarget 00702 { 00703 virtual bool IsSubIndex() const { 00704 return true; 00705 } 00706 }; 00707 /*}}}*/ /*{{{*/ 00709 class OptionalSubIndexTarget : public OptionalIndexTarget 00710 { 00711 virtual bool IsSubIndex() const { 00712 return true; 00713 } 00714 }; 00715 /*}}}*/ 00716 00725 class pkgAcqMetaSig : public pkgAcquire::Item 00726 { 00727 protected: 00729 std::string LastGoodSig; 00730 00732 pkgAcquire::ItemDesc Desc; 00733 00738 std::string RealURI; 00739 00741 std::string MetaIndexURI; 00742 00746 std::string MetaIndexURIDesc; 00747 00751 std::string MetaIndexShortDesc; 00752 00754 indexRecords* MetaIndexParser; 00755 00761 const std::vector<struct IndexTarget*>* IndexTargets; 00762 00763 public: 00764 00765 // Specialized action members 00766 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00767 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00768 pkgAcquire::MethodConfig *Cnf); 00769 virtual std::string Custom600Headers(); 00770 virtual std::string DescURI() {return RealURI; }; 00771 00773 pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc, 00774 std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc, 00775 const std::vector<struct IndexTarget*>* IndexTargets, 00776 indexRecords* MetaIndexParser); 00777 }; 00778 /*}}}*/ 00789 class pkgAcqMetaIndex : public pkgAcquire::Item 00790 { 00791 protected: 00793 pkgAcquire::ItemDesc Desc; 00794 00798 std::string RealURI; 00799 00805 std::string SigFile; 00806 00808 const std::vector<struct IndexTarget*>* IndexTargets; 00809 00811 indexRecords* MetaIndexParser; 00812 00815 bool AuthPass; 00816 // required to deal gracefully with problems caused by incorrect ims hits 00817 bool IMSHit; 00818 00824 bool VerifyVendor(std::string Message); 00825 00835 void RetrievalDone(std::string Message); 00836 00846 void AuthDone(std::string Message); 00847 00856 void QueueIndexes(bool verify); 00857 00858 public: 00859 00860 // Specialized action members 00861 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00862 virtual void Done(std::string Message,unsigned long long Size, std::string Hash, 00863 pkgAcquire::MethodConfig *Cnf); 00864 virtual std::string Custom600Headers(); 00865 virtual std::string DescURI() {return RealURI; }; 00866 00868 pkgAcqMetaIndex(pkgAcquire *Owner, 00869 std::string URI,std::string URIDesc, std::string ShortDesc, 00870 std::string SigFile, 00871 const std::vector<struct IndexTarget*>* IndexTargets, 00872 indexRecords* MetaIndexParser); 00873 }; 00874 /*}}}*/ 00876 class pkgAcqMetaClearSig : public pkgAcqMetaIndex 00877 { 00879 std::string MetaIndexURI; 00880 00882 std::string MetaIndexURIDesc; 00883 00885 std::string MetaIndexShortDesc; 00886 00888 std::string MetaSigURI; 00889 00891 std::string MetaSigURIDesc; 00892 00894 std::string MetaSigShortDesc; 00895 00896 public: 00897 void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00898 virtual std::string Custom600Headers(); 00899 00901 pkgAcqMetaClearSig(pkgAcquire *Owner, 00902 std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc, 00903 std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc, 00904 std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc, 00905 const std::vector<struct IndexTarget*>* IndexTargets, 00906 indexRecords* MetaIndexParser); 00907 }; 00908 /*}}}*/ 00914 class pkgAcqArchive : public pkgAcquire::Item 00915 { 00916 protected: 00918 pkgCache::VerIterator Version; 00919 00921 pkgAcquire::ItemDesc Desc; 00922 00926 pkgSourceList *Sources; 00927 00931 pkgRecords *Recs; 00932 00934 HashString ExpectedHash; 00935 00939 std::string &StoreFilename; 00940 00942 pkgCache::VerFileIterator Vf; 00943 00949 unsigned int Retries; 00950 00954 bool Trusted; 00955 00957 bool QueueNext(); 00958 00959 public: 00960 00961 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00962 virtual void Done(std::string Message,unsigned long long Size,std::string Hash, 00963 pkgAcquire::MethodConfig *Cnf); 00964 virtual std::string DescURI() {return Desc.URI;}; 00965 virtual std::string ShortDesc() {return Desc.ShortDesc;}; 00966 virtual void Finished(); 00967 virtual std::string HashSum() {return ExpectedHash.toStr(); }; 00968 virtual bool IsTrusted(); 00969 00988 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, 00989 pkgRecords *Recs,pkgCache::VerIterator const &Version, 00990 std::string &StoreFilename); 00991 }; 00992 /*}}}*/ 00999 class pkgAcqFile : public pkgAcquire::Item 01000 { 01002 pkgAcquire::ItemDesc Desc; 01003 01005 HashString ExpectedHash; 01006 01010 unsigned int Retries; 01011 01013 bool IsIndexFile; 01014 01015 public: 01016 01017 // Specialized action members 01018 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 01019 virtual void Done(std::string Message,unsigned long long Size,std::string CalcHash, 01020 pkgAcquire::MethodConfig *Cnf); 01021 virtual std::string DescURI() {return Desc.URI;}; 01022 virtual std::string HashSum() {return ExpectedHash.toStr(); }; 01023 virtual std::string Custom600Headers(); 01024 01056 pkgAcqFile(pkgAcquire *Owner, std::string URI, std::string Hash, unsigned long long Size, 01057 std::string Desc, std::string ShortDesc, 01058 const std::string &DestDir="", const std::string &DestFilename="", 01059 bool IsIndexFile=false); 01060 }; 01061 /*}}}*/ 01064 #endif