acquire-item.h 35 KB

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