1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
4 /* ######################################################################
6 Acquire Item - Item to acquire
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.
12 Two item classes are provided to provide functionality for downloading
13 of Index files and downloading of Packages.
15 A Archive class is provided for downloading .deb files. It does Md5
16 checking and source location as well as a retry algorithm.
18 ##################################################################### */
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
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>
31 #pragma interface "apt-pkg/acquire-item.h"
35 class pkgAcquire::Item
39 // Some private helper methods for registering URIs
41 inline void QueueURI(ItemDesc
&Item
)
42 {Owner
->Enqueue(Item
);};
43 inline void Dequeue() {Owner
->Dequeue(this);};
45 // Safe rename function with timestamp preservation
46 void Rename(string From
,string To
);
51 enum {StatIdle
, StatFetching
, StatDone
, StatError
, StatAuthError
} Status
;
53 unsigned long FileSize
;
54 unsigned long PartialSize
;
60 // Number of queues we are inserted into
61 unsigned int QueueCounter
;
63 // File to write the fetch into
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() {};
77 virtual string
MD5Sum() {return string();};
78 pkgAcquire
*GetOwner() {return Owner
;};
79 virtual bool IsTrusted() {return false;};
81 Item(pkgAcquire
*Owner
);
85 // item for index diffs
93 class pkgAcqDiffIndex
: public pkgAcquire::Item
97 pkgAcquire::ItemDesc Desc
;
100 string CurrentPackagesFile
;
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();
112 bool ParseDiffIndex(string IndexDiffFile
);
114 pkgAcqDiffIndex(pkgAcquire
*Owner
,string URI
,string URIDesc
,
115 string ShortDesct
, string ExpectedMD5
);
118 class pkgAcqIndexDiffs
: public pkgAcquire::Item
122 pkgAcquire::ItemDesc Desc
;
126 // this is the SHA-1 sum we expect after the patching
128 vector
<DiffInfo
> available_patches
;
129 enum {StateFetchIndex
,StateFetchDiff
,StateUnzipDiff
,StateApplyDiff
} State
;
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";};
140 bool QueueNextDiff();
141 bool ApplyDiff(string PatchFile
);
142 void Finish(bool allDone
=false);
144 pkgAcqIndexDiffs(pkgAcquire
*Owner
,string URI
,string URIDesc
,
145 string ShortDesct
, string ExpectedMD5
,
146 vector
<DiffInfo
> diffs
=vector
<DiffInfo
>());
149 // Item class for index files
150 class pkgAcqIndex
: public pkgAcquire::Item
156 pkgAcquire::ItemDesc Desc
;
159 string CompressionExtension
;
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
;};
170 pkgAcqIndex(pkgAcquire
*Owner
,string URI
,string URIDesc
,
171 string ShortDesct
, string ExpectedMD5
, string compressExt
="");
182 // Item class for index signatures
183 class pkgAcqMetaSig
: public pkgAcquire::Item
187 pkgAcquire::ItemDesc Desc
;
188 string RealURI
,MetaIndexURI
,MetaIndexURIDesc
,MetaIndexShortDesc
;
189 indexRecords
* MetaIndexParser
;
190 const vector
<struct IndexTarget
*>* IndexTargets
;
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
; };
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
);
207 // Item class for index signatures
208 class pkgAcqMetaIndex
: public pkgAcquire::Item
212 pkgAcquire::ItemDesc Desc
;
213 string RealURI
; // FIXME: is this redundant w/ Desc.URI?
215 const vector
<struct IndexTarget
*>* IndexTargets
;
216 indexRecords
* MetaIndexParser
;
218 // required to deal gracefully with problems caused by incorrect ims hits
221 bool VerifyVendor(string Message
);
222 void RetrievalDone(string Message
);
223 void AuthDone(string Message
);
224 void QueueIndexes(bool verify
);
228 // Specialized action members
229 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
230 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
231 pkgAcquire::MethodConfig
*Cnf
);
232 virtual string
Custom600Headers();
233 virtual string
DescURI() {return RealURI
; };
235 pkgAcqMetaIndex(pkgAcquire
*Owner
,
236 string URI
,string URIDesc
, string ShortDesc
,
238 const vector
<struct IndexTarget
*>* IndexTargets
,
239 indexRecords
* MetaIndexParser
);
242 // Item class for archive files
243 class pkgAcqArchive
: public pkgAcquire::Item
247 // State information for the retry mechanism
248 pkgCache::VerIterator Version
;
249 pkgAcquire::ItemDesc Desc
;
250 pkgSourceList
*Sources
;
253 string
&StoreFilename
;
254 pkgCache::VerFileIterator Vf
;
255 unsigned int Retries
;
258 // Queue the next available file for download.
263 // Specialized action members
264 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
265 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
266 pkgAcquire::MethodConfig
*Cnf
);
267 virtual string
MD5Sum() {return MD5
;};
268 virtual string
DescURI() {return Desc
.URI
;};
269 virtual string
ShortDesc() {return Desc
.ShortDesc
;};
270 virtual void Finished();
271 virtual bool IsTrusted();
273 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
274 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
275 string
&StoreFilename
);
278 // Fetch a generic file to the current directory
279 class pkgAcqFile
: public pkgAcquire::Item
281 pkgAcquire::ItemDesc Desc
;
283 unsigned int Retries
;
287 // Specialized action members
288 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
289 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
290 pkgAcquire::MethodConfig
*Cnf
);
291 virtual string
MD5Sum() {return Md5Hash
;};
292 virtual string
DescURI() {return Desc
.URI
;};
294 // If DestFilename is empty, download to DestDir/<basename> if
295 // DestDir is non-empty, $CWD/<basename> otherwise. If
296 // DestFilename is NOT empty, DestDir is ignored and DestFilename
297 // is the absolute name to which the file should be downloaded.
298 pkgAcqFile(pkgAcquire
*Owner
, string URI
, string MD5
, unsigned long Size
,
299 string Desc
, string ShortDesc
,
300 const string
&DestDir
="", const string
&DestFilename
="");