acquire-item.h 7.5 KB

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