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 00600 std::string GetFinalFilename(std::string const &URI, 00601 std::string const &compExt); 00602 00604 void ReverifyAfterIMS(std::string const &FileName); 00605 00606 public: 00607 00608 // Specialized action members 00609 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00610 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00611 pkgAcquire::MethodConfig *Cnf); 00612 virtual std::string Custom600Headers(); 00613 virtual std::string DescURI() {return Desc.URI;}; 00614 virtual std::string HashSum() {return ExpectedHash.toStr(); }; 00615 00635 pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc, 00636 std::string ShortDesc, HashString ExpectedHash, 00637 std::string compressExt=""); 00638 pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target, 00639 HashString const &ExpectedHash, indexRecords const *MetaIndexParser); 00640 void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc); 00641 }; 00642 /*}}}*/ 00650 class pkgAcqIndexTrans : public pkgAcqIndex 00651 { 00652 public: 00653 00654 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00655 virtual std::string Custom600Headers(); 00656 00668 pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc, 00669 std::string ShortDesc); 00670 pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target, 00671 HashString const &ExpectedHash, indexRecords const *MetaIndexParser); 00672 }; 00673 /*}}}*/ /*{{{*/ 00675 class IndexTarget 00676 { 00677 public: 00679 std::string URI; 00680 00682 std::string Description; 00683 00685 std::string ShortDesc; 00686 00690 std::string MetaKey; 00691 00692 virtual bool IsOptional() const { 00693 return false; 00694 } 00695 virtual bool IsSubIndex() const { 00696 return false; 00697 } 00698 }; 00699 /*}}}*/ /*{{{*/ 00701 class OptionalIndexTarget : public IndexTarget 00702 { 00703 virtual bool IsOptional() const { 00704 return true; 00705 } 00706 }; 00707 /*}}}*/ /*{{{*/ 00709 class SubIndexTarget : public IndexTarget 00710 { 00711 virtual bool IsSubIndex() const { 00712 return true; 00713 } 00714 }; 00715 /*}}}*/ /*{{{*/ 00717 class OptionalSubIndexTarget : public OptionalIndexTarget 00718 { 00719 virtual bool IsSubIndex() const { 00720 return true; 00721 } 00722 }; 00723 /*}}}*/ 00724 00733 class pkgAcqMetaSig : public pkgAcquire::Item 00734 { 00735 protected: 00737 std::string LastGoodSig; 00738 00740 pkgAcquire::ItemDesc Desc; 00741 00746 std::string RealURI; 00747 00749 std::string MetaIndexURI; 00750 00754 std::string MetaIndexURIDesc; 00755 00759 std::string MetaIndexShortDesc; 00760 00762 indexRecords* MetaIndexParser; 00763 00769 const std::vector<struct IndexTarget*>* IndexTargets; 00770 00771 public: 00772 00773 // Specialized action members 00774 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00775 virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash, 00776 pkgAcquire::MethodConfig *Cnf); 00777 virtual std::string Custom600Headers(); 00778 virtual std::string DescURI() {return RealURI; }; 00779 00781 pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc, 00782 std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc, 00783 const std::vector<struct IndexTarget*>* IndexTargets, 00784 indexRecords* MetaIndexParser); 00785 }; 00786 /*}}}*/ 00797 class pkgAcqMetaIndex : public pkgAcquire::Item 00798 { 00799 protected: 00801 pkgAcquire::ItemDesc Desc; 00802 00806 std::string RealURI; 00807 00813 std::string SigFile; 00814 00816 const std::vector<struct IndexTarget*>* IndexTargets; 00817 00819 indexRecords* MetaIndexParser; 00820 00823 bool AuthPass; 00824 // required to deal gracefully with problems caused by incorrect ims hits 00825 bool IMSHit; 00826 00832 bool VerifyVendor(std::string Message); 00833 00843 void RetrievalDone(std::string Message); 00844 00854 void AuthDone(std::string Message); 00855 00864 void QueueIndexes(bool verify); 00865 00866 public: 00867 00868 // Specialized action members 00869 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00870 virtual void Done(std::string Message,unsigned long long Size, std::string Hash, 00871 pkgAcquire::MethodConfig *Cnf); 00872 virtual std::string Custom600Headers(); 00873 virtual std::string DescURI() {return RealURI; }; 00874 00876 pkgAcqMetaIndex(pkgAcquire *Owner, 00877 std::string URI,std::string URIDesc, std::string ShortDesc, 00878 std::string SigFile, 00879 const std::vector<struct IndexTarget*>* IndexTargets, 00880 indexRecords* MetaIndexParser); 00881 }; 00882 /*}}}*/ 00884 class pkgAcqMetaClearSig : public pkgAcqMetaIndex 00885 { 00887 std::string MetaIndexURI; 00888 00890 std::string MetaIndexURIDesc; 00891 00893 std::string MetaIndexShortDesc; 00894 00896 std::string MetaSigURI; 00897 00899 std::string MetaSigURIDesc; 00900 00902 std::string MetaSigShortDesc; 00903 00904 public: 00905 void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00906 virtual std::string Custom600Headers(); 00907 00909 pkgAcqMetaClearSig(pkgAcquire *Owner, 00910 std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc, 00911 std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc, 00912 std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc, 00913 const std::vector<struct IndexTarget*>* IndexTargets, 00914 indexRecords* MetaIndexParser); 00915 }; 00916 /*}}}*/ 00922 class pkgAcqArchive : public pkgAcquire::Item 00923 { 00924 protected: 00926 pkgCache::VerIterator Version; 00927 00929 pkgAcquire::ItemDesc Desc; 00930 00934 pkgSourceList *Sources; 00935 00939 pkgRecords *Recs; 00940 00942 HashString ExpectedHash; 00943 00947 std::string &StoreFilename; 00948 00950 pkgCache::VerFileIterator Vf; 00951 00957 unsigned int Retries; 00958 00962 bool Trusted; 00963 00965 bool QueueNext(); 00966 00967 public: 00968 00969 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 00970 virtual void Done(std::string Message,unsigned long long Size,std::string Hash, 00971 pkgAcquire::MethodConfig *Cnf); 00972 virtual std::string DescURI() {return Desc.URI;}; 00973 virtual std::string ShortDesc() {return Desc.ShortDesc;}; 00974 virtual void Finished(); 00975 virtual std::string HashSum() {return ExpectedHash.toStr(); }; 00976 virtual bool IsTrusted(); 00977 00996 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, 00997 pkgRecords *Recs,pkgCache::VerIterator const &Version, 00998 std::string &StoreFilename); 00999 }; 01000 /*}}}*/ 01007 class pkgAcqFile : public pkgAcquire::Item 01008 { 01010 pkgAcquire::ItemDesc Desc; 01011 01013 HashString ExpectedHash; 01014 01018 unsigned int Retries; 01019 01021 bool IsIndexFile; 01022 01023 public: 01024 01025 // Specialized action members 01026 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf); 01027 virtual void Done(std::string Message,unsigned long long Size,std::string CalcHash, 01028 pkgAcquire::MethodConfig *Cnf); 01029 virtual std::string DescURI() {return Desc.URI;}; 01030 virtual std::string HashSum() {return ExpectedHash.toStr(); }; 01031 virtual std::string Custom600Headers(); 01032 01064 pkgAcqFile(pkgAcquire *Owner, std::string URI, std::string Hash, unsigned long long Size, 01065 std::string Desc, std::string ShortDesc, 01066 const std::string &DestDir="", const std::string &DestFilename="", 01067 bool IsIndexFile=false); 01068 }; 01069 /*}}}*/ 01072 #endif