acquire-method.h 2.8 KB

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