acquire-item.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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 Hash
  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. #include <apt-pkg/hashes.h>
  24. /** \addtogroup acquire
  25. * @{
  26. *
  27. * \file acquire-item.h
  28. */
  29. /** \brief Represents the process by which a pkgAcquire object should {{{
  30. * retrieve a file or a collection of files.
  31. *
  32. * By convention, Item subclasses should insert themselves into the
  33. * acquire queue when they are created by calling QueueURI(), and
  34. * remove themselves by calling Dequeue() when either Done() or
  35. * Failed() is invoked. Item objects are also responsible for
  36. * notifying the download progress indicator (accessible via
  37. * #Owner->Log) of their status.
  38. *
  39. * \see pkgAcquire
  40. */
  41. class pkgAcquire::Item
  42. {
  43. protected:
  44. /** \brief The acquire object with which this item is associated. */
  45. pkgAcquire *Owner;
  46. /** \brief Insert this item into its owner's queue.
  47. *
  48. * \param ItemDesc Metadata about this item (its URI and
  49. * description).
  50. */
  51. inline void QueueURI(ItemDesc &Item)
  52. {Owner->Enqueue(Item);};
  53. /** \brief Remove this item from its owner's queue. */
  54. inline void Dequeue() {Owner->Dequeue(this);};
  55. /** \brief Rename a file without modifying its timestamp.
  56. *
  57. * Many item methods call this as their final action.
  58. *
  59. * \param From The file to be renamed.
  60. *
  61. * \param To The new name of #From. If #To exists it will be
  62. * overwritten.
  63. */
  64. void Rename(string From,string To);
  65. public:
  66. /** \brief The current status of this item. */
  67. enum ItemState
  68. {
  69. /** \brief The item is waiting to be downloaded. */
  70. StatIdle,
  71. /** \brief The item is currently being downloaded. */
  72. StatFetching,
  73. /** \brief The item has been successfully downloaded. */
  74. StatDone,
  75. /** \brief An error was encountered while downloading this
  76. * item.
  77. */
  78. StatError,
  79. /** \brief The item was downloaded but its authenticity could
  80. * not be verified.
  81. */
  82. StatAuthError,
  83. /** \brief The item was could not be downloaded because of
  84. * a transient network error (e.g. network down)
  85. */
  86. StatTransientNetworkError
  87. } Status;
  88. /** \brief Contains a textual description of the error encountered
  89. * if #Status is #StatError or #StatAuthError.
  90. */
  91. string ErrorText;
  92. /** \brief The size of the object to fetch. */
  93. unsigned long FileSize;
  94. /** \brief How much of the object was already fetched. */
  95. unsigned long PartialSize;
  96. /** \brief If not \b NULL, contains the name of a subprocess that
  97. * is operating on this object (for instance, "gzip" or "gpgv").
  98. */
  99. const char *Mode;
  100. /** \brief A client-supplied unique identifier.
  101. *
  102. * This field is initalized to 0; it is meant to be filled in by
  103. * clients that wish to use it to uniquely identify items.
  104. *
  105. * \todo it's unused in apt itself
  106. */
  107. unsigned long ID;
  108. /** \brief If \b true, the entire object has been successfully fetched.
  109. *
  110. * Subclasses should set this to \b true when appropriate.
  111. */
  112. bool Complete;
  113. /** \brief If \b true, the URI of this object is "local".
  114. *
  115. * The only effect of this field is to exclude the object from the
  116. * download progress indicator's overall statistics.
  117. */
  118. bool Local;
  119. /** \brief The number of fetch queues into which this item has been
  120. * inserted.
  121. *
  122. * There is one queue for each source from which an item could be
  123. * downloaded.
  124. *
  125. * \sa pkgAcquire
  126. */
  127. unsigned int QueueCounter;
  128. /** \brief The name of the file into which the retrieved object
  129. * will be written.
  130. */
  131. string DestFile;
  132. /** \brief Invoked by the acquire worker when the object couldn't
  133. * be fetched.
  134. *
  135. * This is a branch of the continuation of the fetch process.
  136. *
  137. * \param Message An RFC822-formatted message from the acquire
  138. * method describing what went wrong. Use LookupTag() to parse
  139. * it.
  140. *
  141. * \param Cnf The method via which the worker tried to fetch this object.
  142. *
  143. * \sa pkgAcqMethod
  144. */
  145. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  146. /** \brief Invoked by the acquire worker when the object was
  147. * fetched successfully.
  148. *
  149. * Note that the object might \e not have been written to
  150. * DestFile; check for the presence of an Alt-Filename entry in
  151. * Message to find the file to which it was really written.
  152. *
  153. * Done is often used to switch from one stage of the processing
  154. * to the next (e.g. fetching, unpacking, copying). It is one
  155. * branch of the continuation of the fetch process.
  156. *
  157. * \param Message Data from the acquire method. Use LookupTag()
  158. * to parse it.
  159. * \param Size The size of the object that was fetched.
  160. * \param Hash The HashSum of the object that was fetched.
  161. * \param Cnf The method via which the object was fetched.
  162. *
  163. * \sa pkgAcqMethod
  164. */
  165. virtual void Done(string Message,unsigned long Size,string Hash,
  166. pkgAcquire::MethodConfig *Cnf);
  167. /** \brief Invoked when the worker starts to fetch this object.
  168. *
  169. * \param Message RFC822-formatted data from the worker process.
  170. * Use LookupTag() to parse it.
  171. *
  172. * \param Size The size of the object being fetched.
  173. *
  174. * \sa pkgAcqMethod
  175. */
  176. virtual void Start(string Message,unsigned long Size);
  177. /** \brief Custom headers to be sent to the fetch process.
  178. *
  179. * \return a string containing RFC822-style headers that are to be
  180. * inserted into the 600 URI Acquire message sent to the fetch
  181. * subprocess. The headers are inserted after a newline-less
  182. * line, so they should (if nonempty) have a leading newline and
  183. * no trailing newline.
  184. */
  185. virtual string Custom600Headers() {return string();};
  186. /** \brief A "descriptive" URI-like string.
  187. *
  188. * \return a URI that should be used to describe what is being fetched.
  189. */
  190. virtual string DescURI() = 0;
  191. /** \brief Short item description.
  192. *
  193. * \return a brief description of the object being fetched.
  194. */
  195. virtual string ShortDesc() {return DescURI();}
  196. /** \brief Invoked by the worker when the download is completely done. */
  197. virtual void Finished() {};
  198. /** \brief HashSum
  199. *
  200. * \return the HashSum of this object, if applicable; otherwise, an
  201. * empty string.
  202. */
  203. virtual string HashSum() {return string();};
  204. /** \return the acquire process with which this item is associated. */
  205. pkgAcquire *GetOwner() {return Owner;};
  206. /** \return \b true if this object is being fetched from a trusted source. */
  207. virtual bool IsTrusted() {return false;};
  208. /** \brief Initialize an item.
  209. *
  210. * Adds the item to the list of items known to the acquire
  211. * process, but does not place it into any fetch queues (you must
  212. * manually invoke QueueURI() to do so).
  213. *
  214. * Initializes all fields of the item other than Owner to 0,
  215. * false, or the empty string.
  216. *
  217. * \param Owner The new owner of this item.
  218. */
  219. Item(pkgAcquire *Owner);
  220. /** \brief Remove this item from its owner's queue by invoking
  221. * pkgAcquire::Remove.
  222. */
  223. virtual ~Item();
  224. };
  225. /*}}}*/
  226. /** \brief Information about an index patch (aka diff). */ /*{{{*/
  227. struct DiffInfo {
  228. /** The filename of the diff. */
  229. string file;
  230. /** The sha1 hash of the diff. */
  231. string sha1;
  232. /** The size of the diff. */
  233. unsigned long size;
  234. };
  235. /*}}}*/
  236. /** \brief An item that is responsible for fetching an index file of {{{
  237. * package list diffs and starting the package list's download.
  238. *
  239. * This item downloads the Index file and parses it, then enqueues
  240. * additional downloads of either the individual patches (using
  241. * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
  242. *
  243. * \sa pkgAcqIndexDiffs, pkgAcqIndex
  244. */
  245. class pkgAcqDiffIndex : public pkgAcquire::Item
  246. {
  247. protected:
  248. /** \brief If \b true, debugging information will be written to std::clog. */
  249. bool Debug;
  250. /** \brief The item that is currently being downloaded. */
  251. pkgAcquire::ItemDesc Desc;
  252. /** \brief The URI of the index file to recreate at our end (either
  253. * by downloading it or by applying partial patches).
  254. */
  255. string RealURI;
  256. /** \brief The Hash that the real index file should have after
  257. * all patches have been applied.
  258. */
  259. HashString ExpectedHash;
  260. /** \brief The index file which will be patched to generate the new
  261. * file.
  262. */
  263. string CurrentPackagesFile;
  264. /** \brief A description of the Packages file (stored in
  265. * pkgAcquire::ItemDesc::Description).
  266. */
  267. string Description;
  268. public:
  269. // Specialized action members
  270. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  271. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  272. pkgAcquire::MethodConfig *Cnf);
  273. virtual string DescURI() {return RealURI + "Index";};
  274. virtual string Custom600Headers();
  275. /** \brief Parse the Index file for a set of Packages diffs.
  276. *
  277. * Parses the Index file and creates additional download items as
  278. * necessary.
  279. *
  280. * \param IndexDiffFile The name of the Index file.
  281. *
  282. * \return \b true if the Index file was successfully parsed, \b
  283. * false otherwise.
  284. */
  285. bool ParseDiffIndex(string IndexDiffFile);
  286. /** \brief Create a new pkgAcqDiffIndex.
  287. *
  288. * \param Owner The Acquire object that owns this item.
  289. *
  290. * \param URI The URI of the list file to download.
  291. *
  292. * \param URIDesc A long description of the list file to download.
  293. *
  294. * \param ShortDesc A short description of the list file to download.
  295. *
  296. * \param ExpectedHash The list file's MD5 signature.
  297. */
  298. pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc,
  299. string ShortDesc, HashString ExpectedHash);
  300. };
  301. /*}}}*/
  302. /** \brief An item that is responsible for fetching all the patches {{{
  303. * that need to be applied to a given package index file.
  304. *
  305. * After downloading and applying a single patch, this item will
  306. * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
  307. * patches. If no patch can be found that applies to an intermediate
  308. * file or if one of the patches cannot be downloaded, falls back to
  309. * downloading the entire package index file using pkgAcqIndex.
  310. *
  311. * \sa pkgAcqDiffIndex, pkgAcqIndex
  312. */
  313. class pkgAcqIndexDiffs : public pkgAcquire::Item
  314. {
  315. private:
  316. /** \brief Queue up the next diff download.
  317. *
  318. * Search for the next available diff that applies to the file
  319. * that currently exists on disk, and enqueue it by calling
  320. * QueueURI().
  321. *
  322. * \return \b true if an applicable diff was found, \b false
  323. * otherwise.
  324. */
  325. bool QueueNextDiff();
  326. /** \brief Handle tasks that must be performed after the item
  327. * finishes downloading.
  328. *
  329. * Dequeues the item and checks the resulting file's md5sum
  330. * against ExpectedHash after the last patch was applied.
  331. * There is no need to check the md5/sha1 after a "normal"
  332. * patch because QueueNextDiff() will check the sha1 later.
  333. *
  334. * \param allDone If \b true, the file was entirely reconstructed,
  335. * and its md5sum is verified.
  336. */
  337. void Finish(bool allDone=false);
  338. protected:
  339. /** \brief If \b true, debugging output will be written to
  340. * std::clog.
  341. */
  342. bool Debug;
  343. /** \brief A description of the item that is currently being
  344. * downloaded.
  345. */
  346. pkgAcquire::ItemDesc Desc;
  347. /** \brief The URI of the package index file that is being
  348. * reconstructed.
  349. */
  350. string RealURI;
  351. /** \brief The HashSum of the package index file that is being
  352. * reconstructed.
  353. */
  354. HashString ExpectedHash;
  355. /** A description of the file being downloaded. */
  356. string Description;
  357. /** The patches that remain to be downloaded, including the patch
  358. * being downloaded right now. This list should be ordered so
  359. * that each diff appears before any diff that depends on it.
  360. *
  361. * \todo These are indexed by sha1sum; why not use some sort of
  362. * dictionary instead of relying on ordering and stripping them
  363. * off the front?
  364. */
  365. vector<DiffInfo> available_patches;
  366. /** The current status of this patch. */
  367. enum DiffState
  368. {
  369. /** \brief The diff is in an unknown state. */
  370. StateFetchUnkown,
  371. /** \brief The diff is currently being fetched. */
  372. StateFetchDiff,
  373. /** \brief The diff is currently being uncompressed. */
  374. StateUnzipDiff,
  375. /** \brief The diff is currently being applied. */
  376. StateApplyDiff
  377. } State;
  378. public:
  379. /** \brief Called when the patch file failed to be downloaded.
  380. *
  381. * This method will fall back to downloading the whole index file
  382. * outright; its arguments are ignored.
  383. */
  384. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  385. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  386. pkgAcquire::MethodConfig *Cnf);
  387. virtual string DescURI() {return RealURI + "Index";};
  388. /** \brief Create an index diff item.
  389. *
  390. * After filling in its basic fields, this invokes Finish(true) if
  391. * #diffs is empty, or QueueNextDiff() otherwise.
  392. *
  393. * \param Owner The pkgAcquire object that owns this item.
  394. *
  395. * \param URI The URI of the package index file being
  396. * reconstructed.
  397. *
  398. * \param URIDesc A long description of this item.
  399. *
  400. * \param ShortDesc A brief description of this item.
  401. *
  402. * \param ExpectedHash The expected md5sum of the completely
  403. * reconstructed package index file; the index file will be tested
  404. * against this value when it is entirely reconstructed.
  405. *
  406. * \param diffs The remaining diffs from the index of diffs. They
  407. * should be ordered so that each diff appears before any diff
  408. * that depends on it.
  409. */
  410. pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc,
  411. string ShortDesc, HashString ExpectedHash,
  412. vector<DiffInfo> diffs=vector<DiffInfo>());
  413. };
  414. /*}}}*/
  415. /** \brief An acquire item that is responsible for fetching an index {{{
  416. * file (e.g., Packages or Sources).
  417. *
  418. * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
  419. *
  420. * \todo Why does pkgAcqIndex have protected members?
  421. */
  422. class pkgAcqIndex : public pkgAcquire::Item
  423. {
  424. protected:
  425. /** \brief If \b true, the index file has been decompressed. */
  426. bool Decompression;
  427. /** \brief If \b true, the partially downloaded file will be
  428. * removed when the download completes.
  429. */
  430. bool Erase;
  431. /** \brief The download request that is currently being
  432. * processed.
  433. */
  434. pkgAcquire::ItemDesc Desc;
  435. /** \brief The object that is actually being fetched (minus any
  436. * compression-related extensions).
  437. */
  438. string RealURI;
  439. /** \brief The expected hashsum of the decompressed index file. */
  440. HashString ExpectedHash;
  441. /** \brief The compression-related file extension that is being
  442. * added to the downloaded file (e.g., ".gz" or ".bz2").
  443. */
  444. string CompressionExtension;
  445. public:
  446. // Specialized action members
  447. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  448. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  449. pkgAcquire::MethodConfig *Cnf);
  450. virtual string Custom600Headers();
  451. virtual string DescURI() {return RealURI + CompressionExtension;};
  452. virtual string HashSum() {return ExpectedHash.toStr(); };
  453. /** \brief Create a pkgAcqIndex.
  454. *
  455. * \param Owner The pkgAcquire object with which this item is
  456. * associated.
  457. *
  458. * \param URI The URI of the index file that is to be downloaded.
  459. *
  460. * \param URIDesc A "URI-style" description of this index file.
  461. *
  462. * \param ShortDesc A brief description of this index file.
  463. *
  464. * \param ExpectedHash The expected hashsum of this index file.
  465. *
  466. * \param compressExt The compression-related extension with which
  467. * this index file should be downloaded, or "" to autodetect
  468. * Compression types can be set with config Acquire::CompressionTypes,
  469. * default is ".lzma" or ".bz2" (if the needed binaries are present)
  470. * fallback is ".gz" or none.
  471. */
  472. pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
  473. string ShortDesc, HashString ExpectedHash, string compressExt="");
  474. };
  475. /*}}}*/
  476. /** \brief An acquire item that is responsible for fetching a {{{
  477. * translated index file.
  478. *
  479. * The only difference from pkgAcqIndex is that transient failures
  480. * are suppressed: no error occurs if the translated index file is
  481. * missing.
  482. */
  483. class pkgAcqIndexTrans : public pkgAcqIndex
  484. {
  485. public:
  486. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  487. /** \brief Create a pkgAcqIndexTrans.
  488. *
  489. * \param Owner The pkgAcquire object with which this item is
  490. * associated.
  491. *
  492. * \param URI The URI of the index file that is to be downloaded.
  493. *
  494. * \param URIDesc A "URI-style" description of this index file.
  495. *
  496. * \param ShortDesc A brief description of this index file.
  497. */
  498. pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
  499. string ShortDesc);
  500. };
  501. /*}}}*/
  502. /** \brief Information about an index file. */ /*{{{*/
  503. struct IndexTarget
  504. {
  505. /** \brief A URI from which the index file can be downloaded. */
  506. string URI;
  507. /** \brief A description of the index file. */
  508. string Description;
  509. /** \brief A shorter description of the index file. */
  510. string ShortDesc;
  511. /** \brief The key by which this index file should be
  512. * looked up within the meta signature file.
  513. */
  514. string MetaKey;
  515. };
  516. /*}}}*/
  517. /** \brief An acquire item that downloads the detached signature {{{
  518. * of a meta-index (Release) file, then queues up the release
  519. * file itself.
  520. *
  521. * \todo Why protected members?
  522. *
  523. * \sa pkgAcqMetaIndex
  524. */
  525. class pkgAcqMetaSig : public pkgAcquire::Item
  526. {
  527. protected:
  528. /** \brief The last good signature file */
  529. string LastGoodSig;
  530. /** \brief The fetch request that is currently being processed. */
  531. pkgAcquire::ItemDesc Desc;
  532. /** \brief The URI of the signature file. Unlike Desc.URI, this is
  533. * never modified; it is used to determine the file that is being
  534. * downloaded.
  535. */
  536. string RealURI;
  537. /** \brief The URI of the meta-index file to be fetched after the signature. */
  538. string MetaIndexURI;
  539. /** \brief A "URI-style" description of the meta-index file to be
  540. * fetched after the signature.
  541. */
  542. string MetaIndexURIDesc;
  543. /** \brief A brief description of the meta-index file to be fetched
  544. * after the signature.
  545. */
  546. string MetaIndexShortDesc;
  547. /** \brief A package-system-specific parser for the meta-index file. */
  548. indexRecords* MetaIndexParser;
  549. /** \brief The index files which should be looked up in the meta-index
  550. * and then downloaded.
  551. *
  552. * \todo Why a list of pointers instead of a list of structs?
  553. */
  554. const vector<struct IndexTarget*>* IndexTargets;
  555. public:
  556. // Specialized action members
  557. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  558. virtual void Done(string Message,unsigned long Size,string Md5Hash,
  559. pkgAcquire::MethodConfig *Cnf);
  560. virtual string Custom600Headers();
  561. virtual string DescURI() {return RealURI; };
  562. /** \brief Create a new pkgAcqMetaSig. */
  563. pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
  564. string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
  565. const vector<struct IndexTarget*>* IndexTargets,
  566. indexRecords* MetaIndexParser);
  567. };
  568. /*}}}*/
  569. /** \brief An item that is responsible for downloading the meta-index {{{
  570. * file (i.e., Release) itself and verifying its signature.
  571. *
  572. * Once the download and verification are complete, the downloads of
  573. * the individual index files are queued up using pkgAcqDiffIndex.
  574. * If the meta-index file had a valid signature, the expected hashsums
  575. * of the index files will be the md5sums listed in the meta-index;
  576. * otherwise, the expected hashsums will be "" (causing the
  577. * authentication of the index files to be bypassed).
  578. */
  579. class pkgAcqMetaIndex : public pkgAcquire::Item
  580. {
  581. protected:
  582. /** \brief The fetch command that is currently being processed. */
  583. pkgAcquire::ItemDesc Desc;
  584. /** \brief The URI that is actually being downloaded; never
  585. * modified by pkgAcqMetaIndex.
  586. */
  587. string RealURI;
  588. /** \brief The file in which the signature for this index was stored.
  589. *
  590. * If empty, the signature and the md5sums of the individual
  591. * indices will not be checked.
  592. */
  593. string SigFile;
  594. /** \brief The index files to download. */
  595. const vector<struct IndexTarget*>* IndexTargets;
  596. /** \brief The parser for the meta-index file. */
  597. indexRecords* MetaIndexParser;
  598. /** \brief If \b true, the index's signature is currently being verified.
  599. */
  600. bool AuthPass;
  601. // required to deal gracefully with problems caused by incorrect ims hits
  602. bool IMSHit;
  603. /** \brief Check that the release file is a release file for the
  604. * correct distribution.
  605. *
  606. * \return \b true if no fatal errors were encountered.
  607. */
  608. bool VerifyVendor(string Message);
  609. /** \brief Called when a file is finished being retrieved.
  610. *
  611. * If the file was not downloaded to DestFile, a copy process is
  612. * set up to copy it to DestFile; otherwise, Complete is set to \b
  613. * true and the file is moved to its final location.
  614. *
  615. * \param Message The message block received from the fetch
  616. * subprocess.
  617. */
  618. void RetrievalDone(string Message);
  619. /** \brief Called when authentication succeeded.
  620. *
  621. * Sanity-checks the authenticated file, queues up the individual
  622. * index files for download, and saves the signature in the lists
  623. * directory next to the authenticated list file.
  624. *
  625. * \param Message The message block received from the fetch
  626. * subprocess.
  627. */
  628. void AuthDone(string Message);
  629. /** \brief Starts downloading the individual index files.
  630. *
  631. * \param verify If \b true, only indices whose expected hashsum
  632. * can be determined from the meta-index will be downloaded, and
  633. * the hashsums of indices will be checked (reporting
  634. * #StatAuthError if there is a mismatch). If verify is \b false,
  635. * no hashsum checking will be performed.
  636. */
  637. void QueueIndexes(bool verify);
  638. public:
  639. // Specialized action members
  640. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  641. virtual void Done(string Message,unsigned long Size, string Hash,
  642. pkgAcquire::MethodConfig *Cnf);
  643. virtual string Custom600Headers();
  644. virtual string DescURI() {return RealURI; };
  645. /** \brief Create a new pkgAcqMetaIndex. */
  646. pkgAcqMetaIndex(pkgAcquire *Owner,
  647. string URI,string URIDesc, string ShortDesc,
  648. string SigFile,
  649. const vector<struct IndexTarget*>* IndexTargets,
  650. indexRecords* MetaIndexParser);
  651. };
  652. /*}}}*/
  653. /** \brief An item that is responsible for fetching a package file. {{{
  654. *
  655. * If the package file already exists in the cache, nothing will be
  656. * done.
  657. */
  658. class pkgAcqArchive : public pkgAcquire::Item
  659. {
  660. protected:
  661. /** \brief The package version being fetched. */
  662. pkgCache::VerIterator Version;
  663. /** \brief The fetch command that is currently being processed. */
  664. pkgAcquire::ItemDesc Desc;
  665. /** \brief The list of sources from which to pick archives to
  666. * download this package from.
  667. */
  668. pkgSourceList *Sources;
  669. /** \brief A package records object, used to look up the file
  670. * corresponding to each version of the package.
  671. */
  672. pkgRecords *Recs;
  673. /** \brief The hashsum of this package. */
  674. HashString ExpectedHash;
  675. /** \brief A location in which the actual filename of the package
  676. * should be stored.
  677. */
  678. string &StoreFilename;
  679. /** \brief The next file for this version to try to download. */
  680. pkgCache::VerFileIterator Vf;
  681. /** \brief How many (more) times to try to find a new source from
  682. * which to download this package version if it fails.
  683. *
  684. * Set from Acquire::Retries.
  685. */
  686. unsigned int Retries;
  687. /** \brief \b true if this version file is being downloaded from a
  688. * trusted source.
  689. */
  690. bool Trusted;
  691. /** \brief Queue up the next available file for this version. */
  692. bool QueueNext();
  693. public:
  694. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  695. virtual void Done(string Message,unsigned long Size,string Hash,
  696. pkgAcquire::MethodConfig *Cnf);
  697. virtual string DescURI() {return Desc.URI;};
  698. virtual string ShortDesc() {return Desc.ShortDesc;};
  699. virtual void Finished();
  700. virtual string HashSum() {return ExpectedHash.toStr(); };
  701. virtual bool IsTrusted();
  702. /** \brief Create a new pkgAcqArchive.
  703. *
  704. * \param Owner The pkgAcquire object with which this item is
  705. * associated.
  706. *
  707. * \param Sources The sources from which to download version
  708. * files.
  709. *
  710. * \param Recs A package records object, used to look up the file
  711. * corresponding to each version of the package.
  712. *
  713. * \param Version The package version to download.
  714. *
  715. * \param StoreFilename A location in which the actual filename of
  716. * the package should be stored. It will be set to a guessed
  717. * basename in the constructor, and filled in with a fully
  718. * qualified filename once the download finishes.
  719. */
  720. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  721. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  722. string &StoreFilename);
  723. };
  724. /*}}}*/
  725. /** \brief Retrieve an arbitrary file to the current directory. {{{
  726. *
  727. * The file is retrieved even if it is accessed via a URL type that
  728. * normally is a NOP, such as "file". If the download fails, the
  729. * partial file is renamed to get a ".FAILED" extension.
  730. */
  731. class pkgAcqFile : public pkgAcquire::Item
  732. {
  733. /** \brief The currently active download process. */
  734. pkgAcquire::ItemDesc Desc;
  735. /** \brief The hashsum of the file to download, if it is known. */
  736. HashString ExpectedHash;
  737. /** \brief How many times to retry the download, set from
  738. * Acquire::Retries.
  739. */
  740. unsigned int Retries;
  741. public:
  742. // Specialized action members
  743. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  744. virtual void Done(string Message,unsigned long Size,string CalcHash,
  745. pkgAcquire::MethodConfig *Cnf);
  746. virtual string DescURI() {return Desc.URI;};
  747. virtual string HashSum() {return ExpectedHash.toStr(); };
  748. /** \brief Create a new pkgAcqFile object.
  749. *
  750. * \param Owner The pkgAcquire object with which this object is
  751. * associated.
  752. *
  753. * \param URI The URI to download.
  754. *
  755. * \param Hash The hashsum of the file to download, if it is known;
  756. * otherwise "".
  757. *
  758. * \param Size The size of the file to download, if it is known;
  759. * otherwise 0.
  760. *
  761. * \param Desc A description of the file being downloaded.
  762. *
  763. * \param ShortDesc A brief description of the file being
  764. * downloaded.
  765. *
  766. * \param DestDir The directory the file should be downloaded into.
  767. *
  768. * \param DestFilename The filename+path the file is downloaded to.
  769. *
  770. *
  771. * If DestFilename is empty, download to DestDir/<basename> if
  772. * DestDir is non-empty, $CWD/<basename> otherwise. If
  773. * DestFilename is NOT empty, DestDir is ignored and DestFilename
  774. * is the absolute name to which the file should be downloaded.
  775. */
  776. pkgAcqFile(pkgAcquire *Owner, string URI, string Hash, unsigned long Size,
  777. string Desc, string ShortDesc,
  778. const string &DestDir="", const string &DestFilename="");
  779. };
  780. /*}}}*/
  781. /** @} */
  782. #endif