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>
32 class pkgAcquire::Item
36 // Some private helper methods for registering URIs
38 inline void QueueURI(ItemDesc
&Item
)
39 {Owner
->Enqueue(Item
);};
40 inline void Dequeue() {Owner
->Dequeue(this);};
42 // Safe rename function with timestamp preservation
43 void Rename(string From
,string To
);
48 enum {StatIdle
, StatFetching
, StatDone
, StatError
, StatAuthError
} Status
;
50 unsigned long FileSize
;
51 unsigned long PartialSize
;
57 // Number of queues we are inserted into
58 unsigned int QueueCounter
;
60 // File to write the fetch into
63 // Action members invoked by the worker
64 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
65 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
66 pkgAcquire::MethodConfig
*Cnf
);
67 virtual void Start(string Message
,unsigned long Size
);
68 virtual string
Custom600Headers() {return string();};
69 virtual string
DescURI() = 0;
70 virtual string
ShortDesc() {return DescURI();}
71 virtual void Finished() {};
74 virtual string
MD5Sum() {return string();};
75 pkgAcquire
*GetOwner() {return Owner
;};
76 virtual bool IsTrusted() {return false;};
78 Item(pkgAcquire
*Owner
);
82 // Item class for index files
83 class pkgAcqIndex
: public pkgAcquire::Item
89 pkgAcquire::ItemDesc Desc
;
92 string CompressionExtension
;
96 // Specialized action members
97 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
98 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
99 pkgAcquire::MethodConfig
*Cnf
);
100 virtual string
Custom600Headers();
101 virtual string
DescURI() {return RealURI
+ CompressionExtension
;};
103 pkgAcqIndex(pkgAcquire
*Owner
,string URI
,string URIDesc
,
104 string ShortDesct
, string ExpectedMD5
, string compressExt
="");
115 // Item class for index signatures
116 class pkgAcqMetaSig
: public pkgAcquire::Item
120 pkgAcquire::ItemDesc Desc
;
121 string RealURI
,MetaIndexURI
,MetaIndexURIDesc
,MetaIndexShortDesc
;
122 indexRecords
* MetaIndexParser
;
123 const vector
<struct IndexTarget
*>* IndexTargets
;
127 // Specialized action members
128 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
129 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
130 pkgAcquire::MethodConfig
*Cnf
);
131 virtual string
Custom600Headers();
132 virtual string
DescURI() {return RealURI
; };
134 pkgAcqMetaSig(pkgAcquire
*Owner
,string URI
,string URIDesc
, string ShortDesc
,
135 string MetaIndexURI
, string MetaIndexURIDesc
, string MetaIndexShortDesc
,
136 const vector
<struct IndexTarget
*>* IndexTargets
,
137 indexRecords
* MetaIndexParser
);
140 // Item class for index signatures
141 class pkgAcqMetaIndex
: public pkgAcquire::Item
145 pkgAcquire::ItemDesc Desc
;
146 string RealURI
; // FIXME: is this redundant w/ Desc.URI?
148 const vector
<struct IndexTarget
*>* IndexTargets
;
149 indexRecords
* MetaIndexParser
;
151 // required to deal gracefully with problems caused by incorrect ims hits
154 bool VerifyVendor(string Message
);
155 void RetrievalDone(string Message
);
156 void AuthDone(string Message
);
157 void QueueIndexes(bool verify
);
161 // Specialized action members
162 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
163 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
164 pkgAcquire::MethodConfig
*Cnf
);
165 virtual string
Custom600Headers();
166 virtual string
DescURI() {return RealURI
; };
168 pkgAcqMetaIndex(pkgAcquire
*Owner
,
169 string URI
,string URIDesc
, string ShortDesc
,
171 const vector
<struct IndexTarget
*>* IndexTargets
,
172 indexRecords
* MetaIndexParser
);
175 // Item class for archive files
176 class pkgAcqArchive
: public pkgAcquire::Item
180 // State information for the retry mechanism
181 pkgCache::VerIterator Version
;
182 pkgAcquire::ItemDesc Desc
;
183 pkgSourceList
*Sources
;
186 string
&StoreFilename
;
187 pkgCache::VerFileIterator Vf
;
188 unsigned int Retries
;
191 // Queue the next available file for download.
196 // Specialized action members
197 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
198 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
199 pkgAcquire::MethodConfig
*Cnf
);
200 virtual string
MD5Sum() {return MD5
;};
201 virtual string
DescURI() {return Desc
.URI
;};
202 virtual string
ShortDesc() {return Desc
.ShortDesc
;};
203 virtual void Finished();
204 virtual bool IsTrusted();
206 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
207 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
208 string
&StoreFilename
);
211 // Fetch a generic file to the current directory
212 class pkgAcqFile
: public pkgAcquire::Item
214 pkgAcquire::ItemDesc Desc
;
216 unsigned int Retries
;
220 // Specialized action members
221 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
222 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
223 pkgAcquire::MethodConfig
*Cnf
);
224 virtual string
MD5Sum() {return Md5Hash
;};
225 virtual string
DescURI() {return Desc
.URI
;};
227 // If DestFilename is empty, download to DestDir/<basename> if
228 // DestDir is non-empty, $CWD/<basename> otherwise. If
229 // DestFilename is NOT empty, DestDir is ignored and DestFilename
230 // is the absolute name to which the file should be downloaded.
231 pkgAcqFile(pkgAcquire
*Owner
, string URI
, string MD5
, unsigned long Size
,
232 string Desc
, string ShortDesc
,
233 const string
&DestDir
="", const string
&DestFilename
="");