acquire-method.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-method.h,v 1.15.2.1 2003/12/24 23:09:17 mdz Exp $
  4. /* ######################################################################
  5. Acquire Method - Method helper class + functions
  6. These functions are designed to be used within the method task to
  7. ease communication with APT.
  8. ##################################################################### */
  9. /*}}}*/
  10. /** \addtogroup acquire
  11. * @{
  12. *
  13. * \file acquire-method.h
  14. */
  15. #ifndef PKGLIB_ACQUIRE_METHOD_H
  16. #define PKGLIB_ACQUIRE_METHOD_H
  17. #include <apt-pkg/configuration.h>
  18. #include <apt-pkg/strutl.h>
  19. class Hashes;
  20. class pkgAcqMethod
  21. {
  22. protected:
  23. struct FetchItem
  24. {
  25. FetchItem *Next;
  26. string Uri;
  27. string DestFile;
  28. time_t LastModified;
  29. bool IndexFile;
  30. bool FailIgnore;
  31. };
  32. struct FetchResult
  33. {
  34. string MD5Sum;
  35. string SHA1Sum;
  36. string SHA256Sum;
  37. vector<string> GPGVOutput;
  38. time_t LastModified;
  39. bool IMSHit;
  40. string Filename;
  41. unsigned long Size;
  42. unsigned long ResumePoint;
  43. void TakeHashes(Hashes &Hash);
  44. FetchResult();
  45. };
  46. // State
  47. vector<string> Messages;
  48. FetchItem *Queue;
  49. FetchItem *QueueBack;
  50. string FailReason;
  51. string UsedMirror;
  52. string IP;
  53. // Handlers for messages
  54. virtual bool Configuration(string Message);
  55. virtual bool Fetch(FetchItem * /*Item*/) {return true;};
  56. // Outgoing messages
  57. void Fail(bool Transient = false);
  58. inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);};
  59. virtual void Fail(string Why, bool Transient = false);
  60. virtual void URIStart(FetchResult &Res);
  61. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  62. bool MediaFail(string Required,string Drive);
  63. virtual void Exit() {};
  64. public:
  65. enum CnfFlags {SingleInstance = (1<<0),
  66. Pipeline = (1<<1), SendConfig = (1<<2),
  67. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  68. Removable = (1<<5)};
  69. void Log(const char *Format,...);
  70. void Status(const char *Format,...);
  71. void Redirect(const string &NewURI);
  72. int Run(bool Single = false);
  73. inline void SetFailReason(string Msg) {FailReason = Msg;};
  74. inline void SetIP(string aIP) {IP = aIP;};
  75. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  76. virtual ~pkgAcqMethod() {};
  77. };
  78. /** @} */
  79. #endif