acquire-method.h 2.8 KB

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