You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1186 lines
38 KiB

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