apt  0.9.7.9
acquire-item.h
Go to the documentation of this file.
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
4 /* ######################################################################
5 
6  Acquire Item - Item to acquire
7 
8  When an item is instantiated it will add it self to the local list in
9  the Owner Acquire class. Derived classes will then call QueueURI to
10  register all the URI's they wish to fetch at the initial moment.
11 
12  Three item classes are provided to provide functionality for
13  downloading of Index, Translation and Packages files.
14 
15  A Archive class is provided for downloading .deb files. It does Hash
16  checking and source location as well as a retry algorithm.
17 
18  ##################################################################### */
19  /*}}}*/
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
22 
23 #include <apt-pkg/acquire.h>
24 #include <apt-pkg/hashes.h>
25 #include <apt-pkg/weakptr.h>
26 #include <apt-pkg/pkgcache.h>
27 
28 #ifndef APT_8_CLEANER_HEADERS
29 #include <apt-pkg/indexfile.h>
30 #include <apt-pkg/vendor.h>
31 #include <apt-pkg/sourcelist.h>
32 #include <apt-pkg/pkgrecords.h>
33 #include <apt-pkg/indexrecords.h>
34 #endif
35 
42 class indexRecords;
43 class pkgRecords;
44 class pkgSourceList;
45 
59 {
60  protected:
61 
64 
70  inline void QueueURI(ItemDesc &Item)
71  {Owner->Enqueue(Item);};
72 
74  inline void Dequeue() {Owner->Dequeue(this);};
75 
85  void Rename(std::string From,std::string To);
86 
87  public:
88 
90  enum ItemState
91  {
94 
97 
100 
105 
110 
115  } Status;
116 
120  std::string ErrorText;
121 
123  unsigned long long FileSize;
124 
126  unsigned long long PartialSize;
127 
131  const char *Mode;
132 
140  unsigned long ID;
141 
146  bool Complete;
147 
153  bool Local;
154  std::string UsedMirror;
155 
164  unsigned int QueueCounter;
165 
169  std::string DestFile;
170 
184  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
185 
205  virtual void Done(std::string Message,unsigned long long Size,std::string Hash,
207 
217  virtual void Start(std::string Message,unsigned long long Size);
218 
227  virtual std::string Custom600Headers() {return std::string();};
228 
233  virtual std::string DescURI() = 0;
238  virtual std::string ShortDesc() {return DescURI();}
239 
241  virtual void Finished() {};
242 
248  virtual std::string HashSum() {return std::string();};
249 
251  pkgAcquire *GetOwner() {return Owner;};
252 
254  virtual bool IsTrusted() {return false;};
255 
256  // report mirror problems
264  void ReportMirrorFailure(std::string FailCode);
265 
266 
279 
283  virtual ~Item();
284 };
285  /*}}}*/ /*{{{*/
287 struct DiffInfo {
289  std::string file;
290 
292  std::string sha1;
293 
295  unsigned long size;
296 };
297  /*}}}*/
305 {
306  protected:
308  bool Debug;
309 
312 
316 
317  public:
318  // Specialized action members
319  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
320  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
322  virtual std::string DescURI() {return Desc.URI;};
323  virtual std::string Custom600Headers();
324  virtual bool ParseIndex(std::string const &IndexFile);
325 
338  pkgAcqSubIndex(pkgAcquire *Owner, std::string const &URI,std::string const &URIDesc,
339  std::string const &ShortDesc, HashString const &ExpectedHash);
340 };
341  /*}}}*/
352 {
353  protected:
355  bool Debug;
356 
359 
363  std::string RealURI;
364 
369 
373  std::string CurrentPackagesFile;
374 
378  std::string Description;
379 
380  public:
381  // Specialized action members
382  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
383  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
385  virtual std::string DescURI() {return RealURI + "Index";};
386  virtual std::string Custom600Headers();
387 
398  bool ParseDiffIndex(std::string IndexDiffFile);
399 
400 
413  pkgAcqDiffIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
414  std::string ShortDesc, HashString ExpectedHash);
415 };
416  /*}}}*/
429 {
430  private:
431 
441  bool QueueNextDiff();
442 
454  void Finish(bool allDone=false);
455 
456  protected:
457 
461  bool Debug;
462 
467 
471  std::string RealURI;
472 
477 
479  std::string Description;
480 
489  std::vector<DiffInfo> available_patches;
490 
492  std::string ServerSha1;
493 
496  {
499 
502 
504  StateUnzipDiff, // FIXME: No longer used
505 
508  } State;
509 
510  public:
511 
517  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
518 
519  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
521  virtual std::string DescURI() {return RealURI + "Index";};
522 
545  pkgAcqIndexDiffs(pkgAcquire *Owner,std::string URI,std::string URIDesc,
546  std::string ShortDesc, HashString ExpectedHash,
547  std::string ServerSha1,
548  std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
549 };
550  /*}}}*/
559 {
560  protected:
561 
564 
568  bool Erase;
569 
575  // FIXME: instead of a bool it should use a verify string that will
576  // then be used in the pkgAcqIndex::Done method to ensure that
577  // the downloaded file contains the expected tag
578  bool Verify;
579 
584 
588  std::string RealURI;
589 
592 
596  std::string CompressionExtension;
597 
600  std::string GetFinalFilename(std::string const &URI,
601  std::string const &compExt);
602 
604  void ReverifyAfterIMS(std::string const &FileName);
605 
606  public:
607 
608  // Specialized action members
609  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
610  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
612  virtual std::string Custom600Headers();
613  virtual std::string DescURI() {return Desc.URI;};
614  virtual std::string HashSum() {return ExpectedHash.toStr(); };
615 
635  pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
636  std::string ShortDesc, HashString ExpectedHash,
637  std::string compressExt="");
638  pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target,
639  HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
640  void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc);
641 };
642  /*}}}*/
651 {
652  public:
653 
654  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
655  virtual std::string Custom600Headers();
656 
668  pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
669  std::string ShortDesc);
670  pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target,
671  HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
672 };
673  /*}}}*/ /*{{{*/
676 {
677  public:
679  std::string URI;
680 
682  std::string Description;
683 
685  std::string ShortDesc;
686 
690  std::string MetaKey;
691 
692  virtual bool IsOptional() const {
693  return false;
694  }
695  virtual bool IsSubIndex() const {
696  return false;
697  }
698 };
699  /*}}}*/ /*{{{*/
702 {
703  virtual bool IsOptional() const {
704  return true;
705  }
706 };
707  /*}}}*/ /*{{{*/
710 {
711  virtual bool IsSubIndex() const {
712  return true;
713  }
714 };
715  /*}}}*/ /*{{{*/
718 {
719  virtual bool IsSubIndex() const {
720  return true;
721  }
722 };
723  /*}}}*/
724 
734 {
735  protected:
737  std::string LastGoodSig;
738 
741 
746  std::string RealURI;
747 
749  std::string MetaIndexURI;
750 
754  std::string MetaIndexURIDesc;
755 
759  std::string MetaIndexShortDesc;
760 
763 
769  const std::vector<struct IndexTarget*>* IndexTargets;
770 
771  public:
772 
773  // Specialized action members
774  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
775  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
777  virtual std::string Custom600Headers();
778  virtual std::string DescURI() {return RealURI; };
779 
781  pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc,
782  std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc,
783  const std::vector<struct IndexTarget*>* IndexTargets,
785 };
786  /*}}}*/
798 {
799  protected:
802 
806  std::string RealURI;
807 
813  std::string SigFile;
814 
816  const std::vector<struct IndexTarget*>* IndexTargets;
817 
820 
823  bool AuthPass;
824  // required to deal gracefully with problems caused by incorrect ims hits
825  bool IMSHit;
826 
832  bool VerifyVendor(std::string Message);
833 
843  void RetrievalDone(std::string Message);
844 
854  void AuthDone(std::string Message);
855 
864  void QueueIndexes(bool verify);
865 
866  public:
867 
868  // Specialized action members
869  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
870  virtual void Done(std::string Message,unsigned long long Size, std::string Hash,
872  virtual std::string Custom600Headers();
873  virtual std::string DescURI() {return RealURI; };
874 
877  std::string URI,std::string URIDesc, std::string ShortDesc,
878  std::string SigFile,
879  const std::vector<struct IndexTarget*>* IndexTargets,
881 };
882  /*}}}*/
885 {
887  std::string MetaIndexURI;
888 
890  std::string MetaIndexURIDesc;
891 
893  std::string MetaIndexShortDesc;
894 
896  std::string MetaSigURI;
897 
899  std::string MetaSigURIDesc;
900 
902  std::string MetaSigShortDesc;
903 
904 public:
905  void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
906  virtual std::string Custom600Headers();
907 
910  std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
911  std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
912  std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
913  const std::vector<struct IndexTarget*>* IndexTargets,
915 };
916  /*}}}*/
923 {
924  protected:
927 
930 
935 
940 
943 
947  std::string &StoreFilename;
948 
951 
957  unsigned int Retries;
958 
962  bool Trusted;
963 
965  bool QueueNext();
966 
967  public:
968 
969  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
970  virtual void Done(std::string Message,unsigned long long Size,std::string Hash,
972  virtual std::string DescURI() {return Desc.URI;};
973  virtual std::string ShortDesc() {return Desc.ShortDesc;};
974  virtual void Finished();
975  virtual std::string HashSum() {return ExpectedHash.toStr(); };
976  virtual bool IsTrusted();
977 
998  std::string &StoreFilename);
999 };
1000  /*}}}*/
1008 {
1010  pkgAcquire::ItemDesc Desc;
1011 
1013  HashString ExpectedHash;
1014 
1018  unsigned int Retries;
1019 
1021  bool IsIndexFile;
1022 
1023  public:
1024 
1025  // Specialized action members
1026  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1027  virtual void Done(std::string Message,unsigned long long Size,std::string CalcHash,
1029  virtual std::string DescURI() {return Desc.URI;};
1030  virtual std::string HashSum() {return ExpectedHash.toStr(); };
1031  virtual std::string Custom600Headers();
1032 
1064  pkgAcqFile(pkgAcquire *Owner, std::string URI, std::string Hash, unsigned long long Size,
1065  std::string Desc, std::string ShortDesc,
1066  const std::string &DestDir="", const std::string &DestFilename="",
1067  bool IsIndexFile=false);
1068 };
1069  /*}}}*/
1072 #endif