apt  0.9.11.4
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 
598  public:
599 
600  // Specialized action members
601  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
602  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
604  virtual std::string Custom600Headers();
605  virtual std::string DescURI() {return Desc.URI;};
606  virtual std::string HashSum() {return ExpectedHash.toStr(); };
607 
627  pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
628  std::string ShortDesc, HashString ExpectedHash,
629  std::string compressExt="");
630  pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target,
631  HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
632  void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc);
633 };
634  /*}}}*/
643 {
644  public:
645 
646  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
647  virtual std::string Custom600Headers();
648 
660  pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
661  std::string ShortDesc);
662  pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target,
663  HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
664 };
665  /*}}}*/ /*{{{*/
668 {
669  public:
671  std::string URI;
672 
674  std::string Description;
675 
677  std::string ShortDesc;
678 
682  std::string MetaKey;
683 
684  virtual bool IsOptional() const {
685  return false;
686  }
687  virtual bool IsSubIndex() const {
688  return false;
689  }
690 };
691  /*}}}*/ /*{{{*/
694 {
695  virtual bool IsOptional() const {
696  return true;
697  }
698 };
699  /*}}}*/ /*{{{*/
702 {
703  virtual bool IsSubIndex() const {
704  return true;
705  }
706 };
707  /*}}}*/ /*{{{*/
710 {
711  virtual bool IsSubIndex() const {
712  return true;
713  }
714 };
715  /*}}}*/
716 
726 {
727  protected:
729  std::string LastGoodSig;
730 
733 
738  std::string RealURI;
739 
741  std::string MetaIndexURI;
742 
746  std::string MetaIndexURIDesc;
747 
751  std::string MetaIndexShortDesc;
752 
755 
761  const std::vector<struct IndexTarget*>* IndexTargets;
762 
763  public:
764 
765  // Specialized action members
766  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
767  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
769  virtual std::string Custom600Headers();
770  virtual std::string DescURI() {return RealURI; };
771 
773  pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc,
774  std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc,
775  const std::vector<struct IndexTarget*>* IndexTargets,
777  virtual ~pkgAcqMetaSig();
778 };
779  /*}}}*/
791 {
792  protected:
795 
799  std::string RealURI;
800 
806  std::string SigFile;
807 
809  const std::vector<struct IndexTarget*>* IndexTargets;
810 
813 
816  bool AuthPass;
817  // required to deal gracefully with problems caused by incorrect ims hits
818  bool IMSHit;
819 
825  bool VerifyVendor(std::string Message);
826 
836  void RetrievalDone(std::string Message);
837 
847  void AuthDone(std::string Message);
848 
857  void QueueIndexes(bool verify);
858 
859  public:
860 
861  // Specialized action members
862  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
863  virtual void Done(std::string Message,unsigned long long Size, std::string Hash,
865  virtual std::string Custom600Headers();
866  virtual std::string DescURI() {return RealURI; };
867 
870  std::string URI,std::string URIDesc, std::string ShortDesc,
871  std::string SigFile,
872  const std::vector<struct IndexTarget*>* IndexTargets,
874 };
875  /*}}}*/
878 {
880  std::string MetaIndexURI;
881 
883  std::string MetaIndexURIDesc;
884 
886  std::string MetaIndexShortDesc;
887 
889  std::string MetaSigURI;
890 
892  std::string MetaSigURIDesc;
893 
895  std::string MetaSigShortDesc;
896 
897 public:
898  void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
899  virtual std::string Custom600Headers();
900 
903  std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
904  std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
905  std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
906  const std::vector<struct IndexTarget*>* IndexTargets,
908  virtual ~pkgAcqMetaClearSig();
909 };
910  /*}}}*/
917 {
918  protected:
921 
924 
929 
934 
937 
941  std::string &StoreFilename;
942 
945 
951  unsigned int Retries;
952 
956  bool Trusted;
957 
959  bool QueueNext();
960 
961  public:
962 
963  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
964  virtual void Done(std::string Message,unsigned long long Size,std::string Hash,
966  virtual std::string DescURI() {return Desc.URI;};
967  virtual std::string ShortDesc() {return Desc.ShortDesc;};
968  virtual void Finished();
969  virtual std::string HashSum() {return ExpectedHash.toStr(); };
970  virtual bool IsTrusted();
971 
992  std::string &StoreFilename);
993 };
994  /*}}}*/
1002 {
1004  pkgAcquire::ItemDesc Desc;
1005 
1007  HashString ExpectedHash;
1008 
1012  unsigned int Retries;
1013 
1015  bool IsIndexFile;
1016 
1017  public:
1018 
1019  // Specialized action members
1020  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1021  virtual void Done(std::string Message,unsigned long long Size,std::string CalcHash,
1023  virtual std::string DescURI() {return Desc.URI;};
1024  virtual std::string HashSum() {return ExpectedHash.toStr(); };
1025  virtual std::string Custom600Headers();
1026 
1058  pkgAcqFile(pkgAcquire *Owner, std::string URI, std::string Hash, unsigned long long Size,
1059  std::string Desc, std::string ShortDesc,
1060  const std::string &DestDir="", const std::string &DestFilename="",
1061  bool IsIndexFile=false);
1062 };
1063  /*}}}*/
1066 #endif