]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | Acquire Item - Item to acquire | |
7 | ||
8 | When an item is instantiated it will add it self to the local list in | |
9 | the Owner Acquire class. Derived classes will then call QueueURI to | |
10 | register all the URI's they wish to fetch at the initial moment. | |
11 | ||
12 | Two item classes are provided to provide functionality for downloading | |
13 | of Index files and downloading of Packages. | |
14 | ||
15 | A Archive class is provided for downloading .deb files. It does Md5 | |
16 | checking and source location as well as a retry algorithm. | |
17 | ||
18 | ##################################################################### */ | |
19 | /*}}}*/ | |
20 | #ifndef PKGLIB_ACQUIRE_ITEM_H | |
21 | #define PKGLIB_ACQUIRE_ITEM_H | |
22 | ||
23 | #include <apt-pkg/acquire.h> | |
24 | #include <apt-pkg/indexfile.h> | |
25 | #include <apt-pkg/vendor.h> | |
26 | #include <apt-pkg/sourcelist.h> | |
27 | #include <apt-pkg/pkgrecords.h> | |
28 | #include <apt-pkg/indexrecords.h> | |
29 | ||
30 | #ifdef __GNUG__ | |
31 | #pragma interface "apt-pkg/acquire-item.h" | |
32 | #endif | |
33 | ||
34 | // Item to acquire | |
35 | class pkgAcquire::Item | |
36 | { | |
37 | protected: | |
38 | ||
39 | // Some private helper methods for registering URIs | |
40 | pkgAcquire *Owner; | |
41 | inline void QueueURI(ItemDesc &Item) | |
42 | {Owner->Enqueue(Item);}; | |
43 | inline void Dequeue() {Owner->Dequeue(this);}; | |
44 | ||
45 | // Safe rename function with timestamp preservation | |
46 | void Rename(string From,string To); | |
47 | ||
48 | public: | |
49 | ||
50 | // State of the item | |
51 | enum {StatIdle, StatFetching, StatDone, StatError, StatAuthError} Status; | |
52 | string ErrorText; | |
53 | unsigned long FileSize; | |
54 | unsigned long PartialSize; | |
55 | const char *Mode; | |
56 | unsigned long ID; | |
57 | bool Complete; | |
58 | bool Local; | |
59 | ||
60 | // Number of queues we are inserted into | |
61 | unsigned int QueueCounter; | |
62 | ||
63 | // File to write the fetch into | |
64 | string DestFile; | |
65 | ||
66 | // Action members invoked by the worker | |
67 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
68 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
69 | pkgAcquire::MethodConfig *Cnf); | |
70 | virtual void Start(string Message,unsigned long Size); | |
71 | virtual string Custom600Headers() {return string();}; | |
72 | virtual string DescURI() = 0; | |
73 | virtual string ShortDesc() {return DescURI();} | |
74 | virtual void Finished() {}; | |
75 | ||
76 | // Inquire functions | |
77 | virtual string MD5Sum() {return string();}; | |
78 | pkgAcquire *GetOwner() {return Owner;}; | |
79 | virtual bool IsTrusted() {return false;}; | |
80 | ||
81 | Item(pkgAcquire *Owner); | |
82 | virtual ~Item(); | |
83 | }; | |
84 | ||
85 | // item for index diffs | |
86 | ||
87 | struct DiffInfo { | |
88 | string file; | |
89 | string sha1; | |
90 | unsigned long size; | |
91 | }; | |
92 | ||
93 | class pkgAcqDiffIndex : public pkgAcquire::Item | |
94 | { | |
95 | protected: | |
96 | bool Debug; | |
97 | pkgAcquire::ItemDesc Desc; | |
98 | string RealURI; | |
99 | string ExpectedMD5; | |
100 | string CurrentPackagesFile; | |
101 | string Description; | |
102 | ||
103 | public: | |
104 | // Specialized action members | |
105 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
106 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
107 | pkgAcquire::MethodConfig *Cnf); | |
108 | virtual string DescURI() {return RealURI + "Index";}; | |
109 | virtual string Custom600Headers(); | |
110 | ||
111 | // helpers | |
112 | bool ParseDiffIndex(string IndexDiffFile); | |
113 | ||
114 | pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc, | |
115 | string ShortDesct, string ExpectedMD5); | |
116 | }; | |
117 | ||
118 | class pkgAcqIndexDiffs : public pkgAcquire::Item | |
119 | { | |
120 | protected: | |
121 | bool Debug; | |
122 | pkgAcquire::ItemDesc Desc; | |
123 | string RealURI; | |
124 | string ExpectedMD5; | |
125 | ||
126 | // this is the SHA-1 sum we expect after the patching | |
127 | string Description; | |
128 | vector<DiffInfo> available_patches; | |
129 | enum {StateFetchIndex,StateFetchDiff,StateUnzipDiff,StateApplyDiff} State; | |
130 | ||
131 | public: | |
132 | ||
133 | // Specialized action members | |
134 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
135 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
136 | pkgAcquire::MethodConfig *Cnf); | |
137 | virtual string DescURI() {return RealURI + "Index";}; | |
138 | ||
139 | // various helpers | |
140 | bool QueueNextDiff(); | |
141 | bool ApplyDiff(string PatchFile); | |
142 | void Finish(bool allDone=false); | |
143 | ||
144 | pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc, | |
145 | string ShortDesct, string ExpectedMD5, | |
146 | vector<DiffInfo> diffs=vector<DiffInfo>()); | |
147 | }; | |
148 | ||
149 | // Item class for index files | |
150 | class pkgAcqIndex : public pkgAcquire::Item | |
151 | { | |
152 | protected: | |
153 | ||
154 | bool Decompression; | |
155 | bool Erase; | |
156 | pkgAcquire::ItemDesc Desc; | |
157 | string RealURI; | |
158 | string ExpectedMD5; | |
159 | string CompressionExtension; | |
160 | ||
161 | public: | |
162 | ||
163 | // Specialized action members | |
164 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
165 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
166 | pkgAcquire::MethodConfig *Cnf); | |
167 | virtual string Custom600Headers(); | |
168 | virtual string DescURI() {return RealURI + CompressionExtension;}; | |
169 | ||
170 | pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc, | |
171 | string ShortDesct, string ExpectedMD5, string compressExt=""); | |
172 | }; | |
173 | ||
174 | struct IndexTarget | |
175 | { | |
176 | string URI; | |
177 | string Description; | |
178 | string ShortDesc; | |
179 | string MetaKey; | |
180 | }; | |
181 | ||
182 | // Item class for index signatures | |
183 | class pkgAcqMetaSig : public pkgAcquire::Item | |
184 | { | |
185 | protected: | |
186 | ||
187 | pkgAcquire::ItemDesc Desc; | |
188 | string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc; | |
189 | indexRecords* MetaIndexParser; | |
190 | const vector<struct IndexTarget*>* IndexTargets; | |
191 | ||
192 | public: | |
193 | ||
194 | // Specialized action members | |
195 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
196 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
197 | pkgAcquire::MethodConfig *Cnf); | |
198 | virtual string Custom600Headers(); | |
199 | virtual string DescURI() {return RealURI; }; | |
200 | ||
201 | pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc, | |
202 | string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc, | |
203 | const vector<struct IndexTarget*>* IndexTargets, | |
204 | indexRecords* MetaIndexParser); | |
205 | }; | |
206 | ||
207 | // Item class for index signatures | |
208 | class pkgAcqMetaIndex : public pkgAcquire::Item | |
209 | { | |
210 | protected: | |
211 | ||
212 | pkgAcquire::ItemDesc Desc; | |
213 | string RealURI; // FIXME: is this redundant w/ Desc.URI? | |
214 | string SigFile; | |
215 | const vector<struct IndexTarget*>* IndexTargets; | |
216 | indexRecords* MetaIndexParser; | |
217 | bool AuthPass; | |
218 | ||
219 | bool VerifyVendor(); | |
220 | void RetrievalDone(string Message); | |
221 | void AuthDone(string Message); | |
222 | void QueueIndexes(bool verify); | |
223 | ||
224 | public: | |
225 | ||
226 | // Specialized action members | |
227 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
228 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
229 | pkgAcquire::MethodConfig *Cnf); | |
230 | virtual string Custom600Headers(); | |
231 | virtual string DescURI() {return RealURI; }; | |
232 | ||
233 | pkgAcqMetaIndex(pkgAcquire *Owner, | |
234 | string URI,string URIDesc, string ShortDesc, | |
235 | string SigFile, | |
236 | const vector<struct IndexTarget*>* IndexTargets, | |
237 | indexRecords* MetaIndexParser); | |
238 | }; | |
239 | ||
240 | // Item class for archive files | |
241 | class pkgAcqArchive : public pkgAcquire::Item | |
242 | { | |
243 | protected: | |
244 | ||
245 | // State information for the retry mechanism | |
246 | pkgCache::VerIterator Version; | |
247 | pkgAcquire::ItemDesc Desc; | |
248 | pkgSourceList *Sources; | |
249 | pkgRecords *Recs; | |
250 | string MD5; | |
251 | string &StoreFilename; | |
252 | pkgCache::VerFileIterator Vf; | |
253 | unsigned int Retries; | |
254 | bool Trusted; | |
255 | ||
256 | // Queue the next available file for download. | |
257 | bool QueueNext(); | |
258 | ||
259 | public: | |
260 | ||
261 | // Specialized action members | |
262 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
263 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
264 | pkgAcquire::MethodConfig *Cnf); | |
265 | virtual string MD5Sum() {return MD5;}; | |
266 | virtual string DescURI() {return Desc.URI;}; | |
267 | virtual string ShortDesc() {return Desc.ShortDesc;}; | |
268 | virtual void Finished(); | |
269 | virtual bool IsTrusted(); | |
270 | ||
271 | pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, | |
272 | pkgRecords *Recs,pkgCache::VerIterator const &Version, | |
273 | string &StoreFilename); | |
274 | }; | |
275 | ||
276 | // Fetch a generic file to the current directory | |
277 | class pkgAcqFile : public pkgAcquire::Item | |
278 | { | |
279 | pkgAcquire::ItemDesc Desc; | |
280 | string Md5Hash; | |
281 | unsigned int Retries; | |
282 | ||
283 | public: | |
284 | ||
285 | // Specialized action members | |
286 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
287 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
288 | pkgAcquire::MethodConfig *Cnf); | |
289 | virtual string MD5Sum() {return Md5Hash;}; | |
290 | virtual string DescURI() {return Desc.URI;}; | |
291 | ||
292 | pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size, | |
293 | string Desc,string ShortDesc); | |
294 | }; | |
295 | ||
296 | #endif |