apt  0.9.12.1
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  protected:
286 
287  enum RenameOnErrorState {
288  HashSumMismatch,
289  SizeMismatch,
290  InvalidFormat
291  };
292 
298  bool RenameOnError(RenameOnErrorState const state);
299 };
300  /*}}}*/ /*{{{*/
302 struct DiffInfo {
304  std::string file;
305 
307  std::string sha1;
308 
310  unsigned long size;
311 };
312  /*}}}*/
320 {
321  protected:
323  bool Debug;
324 
327 
331 
332  public:
333  // Specialized action members
334  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
335  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
337  virtual std::string DescURI() {return Desc.URI;};
338  virtual std::string Custom600Headers();
339  virtual bool ParseIndex(std::string const &IndexFile);
340 
353  pkgAcqSubIndex(pkgAcquire *Owner, std::string const &URI,std::string const &URIDesc,
354  std::string const &ShortDesc, HashString const &ExpectedHash);
355 };
356  /*}}}*/
367 {
368  protected:
370  bool Debug;
371 
374 
378  std::string RealURI;
379 
384 
388  std::string CurrentPackagesFile;
389 
393  std::string Description;
394 
395  public:
396  // Specialized action members
397  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
398  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
400  virtual std::string DescURI() {return RealURI + "Index";};
401  virtual std::string Custom600Headers();
402 
413  bool ParseDiffIndex(std::string IndexDiffFile);
414 
415 
428  pkgAcqDiffIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
429  std::string ShortDesc, HashString ExpectedHash);
430 };
431  /*}}}*/
444 {
445  private:
446 
456  bool QueueNextDiff();
457 
469  void Finish(bool allDone=false);
470 
471  protected:
472 
476  bool Debug;
477 
482 
486  std::string RealURI;
487 
492 
494  std::string Description;
495 
504  std::vector<DiffInfo> available_patches;
505 
507  std::string ServerSha1;
508 
511  {
514 
517 
519  StateUnzipDiff, // FIXME: No longer used
520 
523  } State;
524 
525  public:
526 
532  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
533 
534  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
536  virtual std::string DescURI() {return RealURI + "Index";};
537 
560  pkgAcqIndexDiffs(pkgAcquire *Owner,std::string URI,std::string URIDesc,
561  std::string ShortDesc, HashString ExpectedHash,
562  std::string ServerSha1,
563  std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
564 };
565  /*}}}*/
574 {
575  protected:
576 
579 
583  bool Erase;
584 
590  // FIXME: instead of a bool it should use a verify string that will
591  // then be used in the pkgAcqIndex::Done method to ensure that
592  // the downloaded file contains the expected tag
593  bool Verify;
594 
599 
603  std::string RealURI;
604 
607 
611  std::string CompressionExtension;
612 
613  public:
614 
615  // Specialized action members
616  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
617  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
619  virtual std::string Custom600Headers();
620  virtual std::string DescURI() {return Desc.URI;};
621  virtual std::string HashSum() {return ExpectedHash.toStr(); };
622 
642  pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
643  std::string ShortDesc, HashString ExpectedHash,
644  std::string compressExt="");
645  pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target,
646  HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
647  void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc);
648 };
649  /*}}}*/
658 {
659  public:
660 
661  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
662  virtual std::string Custom600Headers();
663 
675  pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
676  std::string ShortDesc);
677  pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target,
678  HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
679 };
680  /*}}}*/ /*{{{*/
683 {
684  public:
686  std::string URI;
687 
689  std::string Description;
690 
692  std::string ShortDesc;
693 
697  std::string MetaKey;
698 
699  virtual bool IsOptional() const {
700  return false;
701  }
702  virtual bool IsSubIndex() const {
703  return false;
704  }
705 };
706  /*}}}*/ /*{{{*/
709 {
710  virtual bool IsOptional() const {
711  return true;
712  }
713 };
714  /*}}}*/ /*{{{*/
717 {
718  virtual bool IsSubIndex() const {
719  return true;
720  }
721 };
722  /*}}}*/ /*{{{*/
725 {
726  virtual bool IsSubIndex() const {
727  return true;
728  }
729 };
730  /*}}}*/
731 
741 {
742  protected:
744  std::string LastGoodSig;
745 
748 
753  std::string RealURI;
754 
756  std::string MetaIndexURI;
757 
761  std::string MetaIndexURIDesc;
762 
766  std::string MetaIndexShortDesc;
767 
770 
776  const std::vector<struct IndexTarget*>* IndexTargets;
777 
778  public:
779 
780  // Specialized action members
781  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
782  virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
784  virtual std::string Custom600Headers();
785  virtual std::string DescURI() {return RealURI; };
786 
788  pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc,
789  std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc,
790  const std::vector<struct IndexTarget*>* IndexTargets,
792  virtual ~pkgAcqMetaSig();
793 };
794  /*}}}*/
806 {
807  protected:
810 
814  std::string RealURI;
815 
821  std::string SigFile;
822 
824  const std::vector<struct IndexTarget*>* IndexTargets;
825 
828 
831  bool AuthPass;
832  // required to deal gracefully with problems caused by incorrect ims hits
833  bool IMSHit;
834 
840  bool VerifyVendor(std::string Message);
841 
851  void RetrievalDone(std::string Message);
852 
862  void AuthDone(std::string Message);
863 
872  void QueueIndexes(bool verify);
873 
874  public:
875 
876  // Specialized action members
877  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
878  virtual void Done(std::string Message,unsigned long long Size, std::string Hash,
880  virtual std::string Custom600Headers();
881  virtual std::string DescURI() {return RealURI; };
882 
885  std::string URI,std::string URIDesc, std::string ShortDesc,
886  std::string SigFile,
887  const std::vector<struct IndexTarget*>* IndexTargets,
889 };
890  /*}}}*/
893 {
895  std::string MetaIndexURI;
896 
898  std::string MetaIndexURIDesc;
899 
901  std::string MetaIndexShortDesc;
902 
904  std::string MetaSigURI;
905 
907  std::string MetaSigURIDesc;
908 
910  std::string MetaSigShortDesc;
911 
912 public:
913  void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
914  virtual std::string Custom600Headers();
915 
918  std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
919  std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
920  std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
921  const std::vector<struct IndexTarget*>* IndexTargets,
923  virtual ~pkgAcqMetaClearSig();
924 };
925  /*}}}*/
932 {
933  protected:
936 
939 
944 
949 
952 
956  std::string &StoreFilename;
957 
960 
966  unsigned int Retries;
967 
971  bool Trusted;
972 
974  bool QueueNext();
975 
976  public:
977 
978  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
979  virtual void Done(std::string Message,unsigned long long Size,std::string Hash,
981  virtual std::string DescURI() {return Desc.URI;};
982  virtual std::string ShortDesc() {return Desc.ShortDesc;};
983  virtual void Finished();
984  virtual std::string HashSum() {return ExpectedHash.toStr(); };
985  virtual bool IsTrusted();
986 
1007  std::string &StoreFilename);
1008 };
1009  /*}}}*/
1017 {
1019  pkgAcquire::ItemDesc Desc;
1020 
1022  HashString ExpectedHash;
1023 
1027  unsigned int Retries;
1028 
1030  bool IsIndexFile;
1031 
1032  public:
1033 
1034  // Specialized action members
1035  virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1036  virtual void Done(std::string Message,unsigned long long Size,std::string CalcHash,
1038  virtual std::string DescURI() {return Desc.URI;};
1039  virtual std::string HashSum() {return ExpectedHash.toStr(); };
1040  virtual std::string Custom600Headers();
1041 
1073  pkgAcqFile(pkgAcquire *Owner, std::string URI, std::string Hash, unsigned long long Size,
1074  std::string Desc, std::string ShortDesc,
1075  const std::string &DestDir="", const std::string &DestFilename="",
1076  bool IsIndexFile=false);
1077 };
1078  /*}}}*/
1081 #endif