]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | /* ###################################################################### | |
4 | ||
5 | Acquire Method - Method helper class + functions | |
6 | ||
7 | These functions are designed to be used within the method task to | |
8 | ease communication with APT. | |
9 | ||
10 | ##################################################################### */ | |
11 | /*}}}*/ | |
12 | ||
13 | /** \addtogroup acquire | |
14 | * @{ | |
15 | * | |
16 | * \file acquire-method.h | |
17 | */ | |
18 | ||
19 | #ifndef PKGLIB_ACQUIRE_METHOD_H | |
20 | #define PKGLIB_ACQUIRE_METHOD_H | |
21 | ||
22 | #include <apt-pkg/hashes.h> | |
23 | #include <apt-pkg/macros.h> | |
24 | ||
25 | #include <stdarg.h> | |
26 | #include <time.h> | |
27 | ||
28 | #include <string> | |
29 | #include <vector> | |
30 | ||
31 | #ifndef APT_8_CLEANER_HEADERS | |
32 | #include <apt-pkg/configuration.h> | |
33 | #include <apt-pkg/strutl.h> | |
34 | #endif | |
35 | ||
36 | class pkgAcqMethod | |
37 | { | |
38 | protected: | |
39 | ||
40 | struct FetchItem | |
41 | { | |
42 | FetchItem *Next; | |
43 | ||
44 | std::string Uri; | |
45 | std::string DestFile; | |
46 | int DestFileFd; | |
47 | time_t LastModified; | |
48 | bool IndexFile; | |
49 | bool FailIgnore; | |
50 | HashStringList ExpectedHashes; | |
51 | // a maximum size we will download, this can be the exact filesize | |
52 | // for when we know it or a arbitrary limit when we don't know the | |
53 | // filesize (like a InRelease file) | |
54 | unsigned long long MaximumSize; | |
55 | ||
56 | FetchItem(); | |
57 | virtual ~FetchItem(); | |
58 | private: | |
59 | void * const d; | |
60 | }; | |
61 | ||
62 | struct FetchResult | |
63 | { | |
64 | HashStringList Hashes; | |
65 | std::vector<std::string> GPGVOutput; | |
66 | time_t LastModified; | |
67 | bool IMSHit; | |
68 | std::string Filename; | |
69 | unsigned long long Size; | |
70 | unsigned long long ResumePoint; | |
71 | ||
72 | void TakeHashes(class Hashes &Hash); | |
73 | FetchResult(); | |
74 | virtual ~FetchResult(); | |
75 | private: | |
76 | void * const d; | |
77 | }; | |
78 | ||
79 | // State | |
80 | std::vector<std::string> Messages; | |
81 | FetchItem *Queue; | |
82 | FetchItem *QueueBack; | |
83 | std::string FailReason; | |
84 | std::string UsedMirror; | |
85 | std::string IP; | |
86 | ||
87 | // Handlers for messages | |
88 | virtual bool Configuration(std::string Message); | |
89 | virtual bool Fetch(FetchItem * /*Item*/) {return true;}; | |
90 | virtual bool URIAcquire(std::string const &/*Message*/, FetchItem *Itm) { return Fetch(Itm); }; | |
91 | ||
92 | // Outgoing messages | |
93 | void Fail(bool Transient = false); | |
94 | inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);}; | |
95 | virtual void Fail(std::string Why, bool Transient = false); | |
96 | virtual void URIStart(FetchResult &Res); | |
97 | virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0); | |
98 | ||
99 | bool MediaFail(std::string Required,std::string Drive); | |
100 | virtual void Exit() {}; | |
101 | ||
102 | void PrintStatus(char const * const header, const char* Format, va_list &args) const; | |
103 | ||
104 | public: | |
105 | enum CnfFlags {SingleInstance = (1<<0), | |
106 | Pipeline = (1<<1), SendConfig = (1<<2), | |
107 | LocalOnly = (1<<3), NeedsCleanup = (1<<4), | |
108 | Removable = (1<<5)}; | |
109 | ||
110 | void Log(const char *Format,...); | |
111 | void Status(const char *Format,...); | |
112 | ||
113 | void Redirect(const std::string &NewURI); | |
114 | ||
115 | int Run(bool Single = false); | |
116 | inline void SetFailReason(std::string Msg) {FailReason = Msg;}; | |
117 | inline void SetIP(std::string aIP) {IP = aIP;}; | |
118 | ||
119 | pkgAcqMethod(const char *Ver,unsigned long Flags = 0); | |
120 | virtual ~pkgAcqMethod(); | |
121 | void DropPrivsOrDie(); | |
122 | private: | |
123 | APT_HIDDEN void Dequeue(); | |
124 | }; | |
125 | ||
126 | /** @} */ | |
127 | ||
128 | #endif |