acquire-item.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-item.h,v 1.24 2000/01/27 04:15:09 jgg Exp $
  4. /* ######################################################################
  5. Acquire Item - Item to acquire
  6. When an item is instantiated it will add it self to the local list in
  7. the Owner Acquire class. Derived classes will then call QueueURI to
  8. register all the URI's they wish to fetch at the initial moment.
  9. Two item classes are provided to provide functionality for downloading
  10. of Index files and downloading of Packages.
  11. A Archive class is provided for downloading .deb files. It does Md5
  12. checking and source location as well as a retry algorithm.
  13. ##################################################################### */
  14. /*}}}*/
  15. #ifndef PKGLIB_ACQUIRE_ITEM_H
  16. #define PKGLIB_ACQUIRE_ITEM_H
  17. #include <apt-pkg/acquire.h>
  18. #include <apt-pkg/sourcelist.h>
  19. #include <apt-pkg/pkgrecords.h>
  20. #ifdef __GNUG__
  21. #pragma interface "apt-pkg/acquire-item.h"
  22. #endif
  23. // Item to acquire
  24. class pkgAcquire::Item
  25. {
  26. protected:
  27. // Some private helper methods for registering URIs
  28. pkgAcquire *Owner;
  29. inline void QueueURI(ItemDesc &Item)
  30. {Owner->Enqueue(Item);};
  31. inline void Dequeue() {Owner->Dequeue(this);};
  32. // Safe rename function with timestamp preservation
  33. void Rename(string From,string To);
  34. public:
  35. // State of the item
  36. enum {StatIdle, StatFetching, StatDone, StatError} Status;
  37. string ErrorText;
  38. unsigned long FileSize;
  39. unsigned long PartialSize;
  40. char *Mode;
  41. unsigned long ID;
  42. bool Complete;
  43. bool Local;
  44. // Number of queues we are inserted into
  45. unsigned int QueueCounter;
  46. // File to write the fetch into
  47. string DestFile;
  48. // Action members invoked by the worker
  49. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  50. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  51. pkgAcquire::MethodConfig *Cnf);
  52. virtual void Start(string Message,unsigned long Size);
  53. virtual string Custom600Headers() {return string();};
  54. virtual string DescURI() = 0;
  55. virtual void Finished() {};
  56. // Inquire functions
  57. virtual string MD5Sum() {return string();};
  58. pkgAcquire *GetOwner() {return Owner;};
  59. Item(pkgAcquire *Owner);
  60. virtual ~Item();
  61. };
  62. // Item class for index files
  63. class pkgAcqIndex : public pkgAcquire::Item
  64. {
  65. protected:
  66. const pkgSourceList::Item *Location;
  67. bool Decompression;
  68. bool Erase;
  69. pkgAcquire::ItemDesc Desc;
  70. public:
  71. // Specialized action members
  72. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  73. pkgAcquire::MethodConfig *Cnf);
  74. virtual string Custom600Headers();
  75. virtual string DescURI() {return Location->PackagesURI();};
  76. pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location);
  77. };
  78. // Item class for index files
  79. class pkgAcqIndexRel : public pkgAcquire::Item
  80. {
  81. protected:
  82. const pkgSourceList::Item *Location;
  83. pkgAcquire::ItemDesc Desc;
  84. public:
  85. // Specialized action members
  86. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  87. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  88. pkgAcquire::MethodConfig *Cnf);
  89. virtual string Custom600Headers();
  90. virtual string DescURI() {return Location->ReleaseURI();};
  91. pkgAcqIndexRel(pkgAcquire *Owner,const pkgSourceList::Item *Location);
  92. };
  93. // Item class for archive files
  94. class pkgAcqArchive : public pkgAcquire::Item
  95. {
  96. protected:
  97. // State information for the retry mechanism
  98. pkgCache::VerIterator Version;
  99. pkgAcquire::ItemDesc Desc;
  100. pkgSourceList *Sources;
  101. pkgRecords *Recs;
  102. string MD5;
  103. string &StoreFilename;
  104. pkgCache::VerFileIterator Vf;
  105. unsigned int Retries;
  106. // Queue the next available file for download.
  107. bool QueueNext();
  108. public:
  109. // Specialized action members
  110. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  111. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  112. pkgAcquire::MethodConfig *Cnf);
  113. virtual string MD5Sum() {return MD5;};
  114. virtual string DescURI() {return Desc.URI;};
  115. virtual void Finished();
  116. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  117. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  118. string &StoreFilename);
  119. };
  120. // Fetch a generic file to the current directory
  121. class pkgAcqFile : public pkgAcquire::Item
  122. {
  123. pkgAcquire::ItemDesc Desc;
  124. string Md5Hash;
  125. unsigned int Retries;
  126. public:
  127. // Specialized action members
  128. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  129. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  130. pkgAcquire::MethodConfig *Cnf);
  131. virtual string MD5Sum() {return Md5Hash;};
  132. virtual string DescURI() {return Desc.URI;};
  133. pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
  134. string Desc,string ShortDesc);
  135. };
  136. #endif