acquire-method.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef PKGLIB_ACQUIRE_METHOD_H
  11. #define PKGLIB_ACQUIRE_METHOD_H
  12. #include <apt-pkg/configuration.h>
  13. #include <apt-pkg/strutl.h>
  14. #ifdef __GNUG__
  15. #pragma interface "apt-pkg/acquire-method.h"
  16. #endif
  17. class Hashes;
  18. class pkgAcqMethod
  19. {
  20. protected:
  21. struct FetchItem
  22. {
  23. FetchItem *Next;
  24. string Uri;
  25. string DestFile;
  26. time_t LastModified;
  27. bool IndexFile;
  28. string ExpectedMD5;
  29. };
  30. struct FetchResult
  31. {
  32. string MD5Sum;
  33. string SHA1Sum;
  34. vector<string> GPGVOutput;
  35. time_t LastModified;
  36. bool IMSHit;
  37. string Filename;
  38. unsigned long Size;
  39. unsigned long ResumePoint;
  40. void TakeHashes(Hashes &Hash);
  41. FetchResult();
  42. };
  43. // State
  44. vector<string> Messages;
  45. FetchItem *Queue;
  46. FetchItem *QueueBack;
  47. string FailReason;
  48. string UsedMirror;
  49. string IP;
  50. // Handlers for messages
  51. virtual bool Configuration(string Message);
  52. virtual bool Fetch(FetchItem * /*Item*/) {return true;};
  53. // Outgoing messages
  54. void Fail(bool Transient = false);
  55. inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);};
  56. virtual void Fail(string Why, bool Transient = false);
  57. virtual void URIStart(FetchResult &Res);
  58. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  59. bool MediaFail(string Required,string Drive);
  60. virtual void Exit() {};
  61. public:
  62. enum CnfFlags {SingleInstance = (1<<0),
  63. Pipeline = (1<<1), SendConfig = (1<<2),
  64. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  65. Removable = (1<<5)};
  66. void Log(const char *Format,...);
  67. void Status(const char *Format,...);
  68. int Run(bool Single = false);
  69. inline void SetFailReason(string Msg) {FailReason = Msg;};
  70. inline void SetIP(string aIP) {IP = aIP;};
  71. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  72. virtual ~pkgAcqMethod() {};
  73. };
  74. #endif