acquire-item.h 6.9 KB

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