acquire-item.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. Three item classes are provided to provide functionality for
  10. downloading of Index, Translation and Packages files.
  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. #ifdef __GNUG__
  24. #pragma interface "apt-pkg/acquire-item.h"
  25. #endif
  26. // Item to acquire
  27. class pkgAcquire::Item
  28. {
  29. protected:
  30. // Some private helper methods for registering URIs
  31. pkgAcquire *Owner;
  32. inline void QueueURI(ItemDesc &Item)
  33. {Owner->Enqueue(Item);};
  34. inline void Dequeue() {Owner->Dequeue(this);};
  35. // Safe rename function with timestamp preservation
  36. void Rename(string From,string To);
  37. public:
  38. // State of the item
  39. enum {StatIdle, StatFetching, StatDone, StatError,
  40. StatAuthError, StatTransientNetworkError} Status;
  41. string ErrorText;
  42. unsigned long FileSize;
  43. unsigned long PartialSize;
  44. const char *Mode;
  45. unsigned long ID;
  46. bool Complete;
  47. bool Local;
  48. // Number of queues we are inserted into
  49. unsigned int QueueCounter;
  50. // File to write the fetch into
  51. string DestFile;
  52. // Action members invoked by the worker
  53. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  54. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  55. pkgAcquire::MethodConfig *Cnf);
  56. virtual void Start(string Message,unsigned long Size);
  57. virtual string Custom600Headers() {return string();};
  58. virtual string DescURI() = 0;
  59. virtual string ShortDesc() {return DescURI();}
  60. virtual void Finished() {};
  61. // Inquire functions
  62. virtual string MD5Sum() {return string();};
  63. pkgAcquire *GetOwner() {return Owner;};
  64. virtual bool IsTrusted() {return false;};
  65. Item(pkgAcquire *Owner);
  66. virtual ~Item();
  67. };
  68. // Item class for index files
  69. class pkgAcqIndex : public pkgAcquire::Item
  70. {
  71. protected:
  72. bool Decompression;
  73. bool Erase;
  74. pkgAcquire::ItemDesc Desc;
  75. string RealURI;
  76. string ExpectedMD5;
  77. string CompressionExtension;
  78. public:
  79. // Specialized action members
  80. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  81. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  82. pkgAcquire::MethodConfig *Cnf);
  83. virtual string Custom600Headers();
  84. virtual string DescURI() {return RealURI + CompressionExtension;};
  85. pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
  86. string ShortDesct, string ExpectedMD5, string compressExt="");
  87. };
  88. // Item class for translated package index files
  89. class pkgAcqIndexTrans : public pkgAcqIndex
  90. {
  91. public:
  92. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  93. pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
  94. string ShortDesct);
  95. };
  96. struct IndexTarget
  97. {
  98. string URI;
  99. string Description;
  100. string ShortDesc;
  101. string MetaKey;
  102. };
  103. // Item class for index signatures
  104. class pkgAcqMetaSig : public pkgAcquire::Item
  105. {
  106. protected:
  107. pkgAcquire::ItemDesc Desc;
  108. string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
  109. indexRecords* MetaIndexParser;
  110. const vector<struct IndexTarget*>* IndexTargets;
  111. public:
  112. // Specialized action members
  113. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  114. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  115. pkgAcquire::MethodConfig *Cnf);
  116. virtual string Custom600Headers();
  117. virtual string DescURI() {return RealURI; };
  118. pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
  119. string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
  120. const vector<struct IndexTarget*>* IndexTargets,
  121. indexRecords* MetaIndexParser);
  122. };
  123. // Item class for index signatures
  124. class pkgAcqMetaIndex : public pkgAcquire::Item
  125. {
  126. protected:
  127. pkgAcquire::ItemDesc Desc;
  128. string RealURI; // FIXME: is this redundant w/ Desc.URI?
  129. string SigFile;
  130. const vector<struct IndexTarget*>* IndexTargets;
  131. indexRecords* MetaIndexParser;
  132. bool AuthPass;
  133. // required to deal gracefully with problems caused by incorrect ims hits
  134. bool IMSHit;
  135. bool VerifyVendor(string Message);
  136. void RetrievalDone(string Message);
  137. void AuthDone(string Message);
  138. void QueueIndexes(bool verify);
  139. public:
  140. // Specialized action members
  141. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  142. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  143. pkgAcquire::MethodConfig *Cnf);
  144. virtual string Custom600Headers();
  145. virtual string DescURI() {return RealURI; };
  146. pkgAcqMetaIndex(pkgAcquire *Owner,
  147. string URI,string URIDesc, string ShortDesc,
  148. string SigFile,
  149. const vector<struct IndexTarget*>* IndexTargets,
  150. indexRecords* MetaIndexParser);
  151. };
  152. // Item class for archive files
  153. class pkgAcqArchive : public pkgAcquire::Item
  154. {
  155. protected:
  156. // State information for the retry mechanism
  157. pkgCache::VerIterator Version;
  158. pkgAcquire::ItemDesc Desc;
  159. pkgSourceList *Sources;
  160. pkgRecords *Recs;
  161. string MD5;
  162. string &StoreFilename;
  163. pkgCache::VerFileIterator Vf;
  164. unsigned int Retries;
  165. bool Trusted;
  166. // Queue the next available file for download.
  167. bool QueueNext();
  168. public:
  169. // Specialized action members
  170. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  171. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  172. pkgAcquire::MethodConfig *Cnf);
  173. virtual string MD5Sum() {return MD5;};
  174. virtual string DescURI() {return Desc.URI;};
  175. virtual string ShortDesc() {return Desc.ShortDesc;};
  176. virtual void Finished();
  177. virtual bool IsTrusted();
  178. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  179. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  180. string &StoreFilename);
  181. };
  182. // Fetch a generic file to the current directory
  183. class pkgAcqFile : public pkgAcquire::Item
  184. {
  185. pkgAcquire::ItemDesc Desc;
  186. string Md5Hash;
  187. unsigned int Retries;
  188. public:
  189. // Specialized action members
  190. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  191. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  192. pkgAcquire::MethodConfig *Cnf);
  193. virtual string MD5Sum() {return Md5Hash;};
  194. virtual string DescURI() {return Desc.URI;};
  195. // If DestFilename is empty, download to DestDir/<basename> if
  196. // DestDir is non-empty, $CWD/<basename> otherwise. If
  197. // DestFilename is NOT empty, DestDir is ignored and DestFilename
  198. // is the absolute name to which the file should be downloaded.
  199. pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size,
  200. string Desc, string ShortDesc,
  201. const string &DestDir="", const string &DestFilename="");
  202. };
  203. #endif