acquire-item.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. 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/indexfile.h>
  19. #include <apt-pkg/vendor.h>
  20. #include <apt-pkg/sourcelist.h>
  21. #include <apt-pkg/pkgrecords.h>
  22. #include <apt-pkg/indexrecords.h>
  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, StatAuthError} Status;
  37. string ErrorText;
  38. unsigned long FileSize;
  39. unsigned long PartialSize;
  40. const 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 string ShortDesc() {return DescURI();}
  56. virtual void Finished() {};
  57. // Inquire functions
  58. virtual string MD5Sum() {return string();};
  59. pkgAcquire *GetOwner() {return Owner;};
  60. virtual bool IsTrusted() {return false;};
  61. Item(pkgAcquire *Owner);
  62. virtual ~Item();
  63. };
  64. // Item class for index files
  65. class pkgAcqIndex : public pkgAcquire::Item
  66. {
  67. protected:
  68. bool Decompression;
  69. bool Erase;
  70. pkgAcquire::ItemDesc Desc;
  71. string RealURI;
  72. string ExpectedMD5;
  73. string CompressionExtension;
  74. public:
  75. // Specialized action members
  76. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  77. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  78. pkgAcquire::MethodConfig *Cnf);
  79. virtual string Custom600Headers();
  80. virtual string DescURI() {return RealURI + CompressionExtension;};
  81. pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
  82. string ShortDesct, string ExpectedMD5, string compressExt="");
  83. };
  84. struct IndexTarget
  85. {
  86. string URI;
  87. string Description;
  88. string ShortDesc;
  89. string MetaKey;
  90. };
  91. // Item class for index signatures
  92. class pkgAcqMetaSig : public pkgAcquire::Item
  93. {
  94. protected:
  95. pkgAcquire::ItemDesc Desc;
  96. string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
  97. indexRecords* MetaIndexParser;
  98. const vector<struct IndexTarget*>* IndexTargets;
  99. public:
  100. // Specialized action members
  101. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  102. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  103. pkgAcquire::MethodConfig *Cnf);
  104. virtual string Custom600Headers();
  105. virtual string DescURI() {return RealURI; };
  106. pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
  107. string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
  108. const vector<struct IndexTarget*>* IndexTargets,
  109. indexRecords* MetaIndexParser);
  110. };
  111. // Item class for index signatures
  112. class pkgAcqMetaIndex : public pkgAcquire::Item
  113. {
  114. protected:
  115. pkgAcquire::ItemDesc Desc;
  116. string RealURI; // FIXME: is this redundant w/ Desc.URI?
  117. string SigFile;
  118. const vector<struct IndexTarget*>* IndexTargets;
  119. indexRecords* MetaIndexParser;
  120. bool AuthPass;
  121. // required to deal gracefully with problems caused by incorrect ims hits
  122. bool IMSHit;
  123. bool VerifyVendor(string Message);
  124. void RetrievalDone(string Message);
  125. void AuthDone(string Message);
  126. void QueueIndexes(bool verify);
  127. public:
  128. // Specialized action members
  129. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  130. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  131. pkgAcquire::MethodConfig *Cnf);
  132. virtual string Custom600Headers();
  133. virtual string DescURI() {return RealURI; };
  134. pkgAcqMetaIndex(pkgAcquire *Owner,
  135. string URI,string URIDesc, string ShortDesc,
  136. string SigFile,
  137. const vector<struct IndexTarget*>* IndexTargets,
  138. indexRecords* MetaIndexParser);
  139. };
  140. // Item class for archive files
  141. class pkgAcqArchive : public pkgAcquire::Item
  142. {
  143. protected:
  144. // State information for the retry mechanism
  145. pkgCache::VerIterator Version;
  146. pkgAcquire::ItemDesc Desc;
  147. pkgSourceList *Sources;
  148. pkgRecords *Recs;
  149. string MD5;
  150. string &StoreFilename;
  151. pkgCache::VerFileIterator Vf;
  152. unsigned int Retries;
  153. bool Trusted;
  154. // Queue the next available file for download.
  155. bool QueueNext();
  156. public:
  157. // Specialized action members
  158. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  159. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  160. pkgAcquire::MethodConfig *Cnf);
  161. virtual string MD5Sum() {return MD5;};
  162. virtual string DescURI() {return Desc.URI;};
  163. virtual string ShortDesc() {return Desc.ShortDesc;};
  164. virtual void Finished();
  165. virtual bool IsTrusted();
  166. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  167. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  168. string &StoreFilename);
  169. };
  170. // Fetch a generic file to the current directory
  171. class pkgAcqFile : public pkgAcquire::Item
  172. {
  173. pkgAcquire::ItemDesc Desc;
  174. string Md5Hash;
  175. unsigned int Retries;
  176. public:
  177. // Specialized action members
  178. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  179. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  180. pkgAcquire::MethodConfig *Cnf);
  181. virtual string MD5Sum() {return Md5Hash;};
  182. virtual string DescURI() {return Desc.URI;};
  183. // If DestFilename is empty, download to DestDir/<basename> if
  184. // DestDir is non-empty, $CWD/<basename> otherwise. If
  185. // DestFilename is NOT empty, DestDir is ignored and DestFilename
  186. // is the absolute name to which the file should be downloaded.
  187. pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size,
  188. string Desc, string ShortDesc,
  189. const string &DestDir="", const string &DestFilename="");
  190. };
  191. #endif