acquire-method.h 2.8 KB

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