acquire-method.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #include <stdarg.h>
  20. class Hashes;
  21. class pkgAcqMethod
  22. {
  23. protected:
  24. struct FetchItem
  25. {
  26. FetchItem *Next;
  27. string Uri;
  28. string DestFile;
  29. time_t LastModified;
  30. bool IndexFile;
  31. bool FailIgnore;
  32. };
  33. struct FetchResult
  34. {
  35. string MD5Sum;
  36. string SHA1Sum;
  37. string SHA256Sum;
  38. string SHA512Sum;
  39. vector<string> GPGVOutput;
  40. time_t LastModified;
  41. bool IMSHit;
  42. string Filename;
  43. unsigned long long Size;
  44. unsigned long long ResumePoint;
  45. void TakeHashes(Hashes &Hash);
  46. FetchResult();
  47. };
  48. // State
  49. vector<string> Messages;
  50. FetchItem *Queue;
  51. FetchItem *QueueBack;
  52. string FailReason;
  53. string UsedMirror;
  54. string IP;
  55. // Handlers for messages
  56. virtual bool Configuration(string Message);
  57. virtual bool Fetch(FetchItem * /*Item*/) {return true;};
  58. // Outgoing messages
  59. void Fail(bool Transient = false);
  60. inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);};
  61. virtual void Fail(string Why, bool Transient = false);
  62. virtual void URIStart(FetchResult &Res);
  63. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  64. bool MediaFail(string Required,string Drive);
  65. virtual void Exit() {};
  66. void PrintStatus(char const * const header, const char* Format, va_list &args) const;
  67. public:
  68. enum CnfFlags {SingleInstance = (1<<0),
  69. Pipeline = (1<<1), SendConfig = (1<<2),
  70. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  71. Removable = (1<<5)};
  72. void Log(const char *Format,...);
  73. void Status(const char *Format,...);
  74. void Redirect(const string &NewURI);
  75. int Run(bool Single = false);
  76. inline void SetFailReason(string Msg) {FailReason = Msg;};
  77. inline void SetIP(string aIP) {IP = aIP;};
  78. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  79. virtual ~pkgAcqMethod() {};
  80. };
  81. /** @} */
  82. #endif