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
,
52 StatAuthError
, StatTransientNetworkError
} Status
;
54 unsigned long FileSize
;
55 unsigned long PartialSize
;
61 // Number of queues we are inserted into
62 unsigned int QueueCounter
;
64 // File to write the fetch into
67 // Action members invoked by the worker
68 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
69 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
70 pkgAcquire::MethodConfig
*Cnf
);
71 virtual void Start(string Message
,unsigned long Size
);
72 virtual string
Custom600Headers() {return string();};
73 virtual string
DescURI() = 0;
74 virtual string
ShortDesc() {return DescURI();}
75 virtual void Finished() {};
78 virtual string
MD5Sum() {return string();};
79 pkgAcquire
*GetOwner() {return Owner
;};
80 virtual bool IsTrusted() {return false;};
82 Item(pkgAcquire
*Owner
);
86 // Item class for index files
87 class pkgAcqIndex
: public pkgAcquire::Item
93 pkgAcquire::ItemDesc Desc
;
96 string CompressionExtension
;
100 // Specialized action members
101 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
102 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
103 pkgAcquire::MethodConfig
*Cnf
);
104 virtual string
Custom600Headers();
105 virtual string
DescURI() {return RealURI
+ CompressionExtension
;};
107 pkgAcqIndex(pkgAcquire
*Owner
,string URI
,string URIDesc
,
108 string ShortDesct
, string ExpectedMD5
, string compressExt
="");
119 // Item class for index signatures
120 class pkgAcqMetaSig
: public pkgAcquire::Item
124 pkgAcquire::ItemDesc Desc
;
125 string RealURI
,MetaIndexURI
,MetaIndexURIDesc
,MetaIndexShortDesc
;
126 indexRecords
* MetaIndexParser
;
127 const vector
<struct IndexTarget
*>* IndexTargets
;
131 // Specialized action members
132 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
133 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
134 pkgAcquire::MethodConfig
*Cnf
);
135 virtual string
Custom600Headers();
136 virtual string
DescURI() {return RealURI
; };
138 pkgAcqMetaSig(pkgAcquire
*Owner
,string URI
,string URIDesc
, string ShortDesc
,
139 string MetaIndexURI
, string MetaIndexURIDesc
, string MetaIndexShortDesc
,
140 const vector
<struct IndexTarget
*>* IndexTargets
,
141 indexRecords
* MetaIndexParser
);
144 // Item class for index signatures
145 class pkgAcqMetaIndex
: public pkgAcquire::Item
149 pkgAcquire::ItemDesc Desc
;
150 string RealURI
; // FIXME: is this redundant w/ Desc.URI?
152 const vector
<struct IndexTarget
*>* IndexTargets
;
153 indexRecords
* MetaIndexParser
;
155 // required to deal gracefully with problems caused by incorrect ims hits
158 bool VerifyVendor(string Message
);
159 void RetrievalDone(string Message
);
160 void AuthDone(string Message
);
161 void QueueIndexes(bool verify
);
165 // Specialized action members
166 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
167 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
168 pkgAcquire::MethodConfig
*Cnf
);
169 virtual string
Custom600Headers();
170 virtual string
DescURI() {return RealURI
; };
172 pkgAcqMetaIndex(pkgAcquire
*Owner
,
173 string URI
,string URIDesc
, string ShortDesc
,
175 const vector
<struct IndexTarget
*>* IndexTargets
,
176 indexRecords
* MetaIndexParser
);
179 // Item class for archive files
180 class pkgAcqArchive
: public pkgAcquire::Item
184 // State information for the retry mechanism
185 pkgCache::VerIterator Version
;
186 pkgAcquire::ItemDesc Desc
;
187 pkgSourceList
*Sources
;
190 string
&StoreFilename
;
191 pkgCache::VerFileIterator Vf
;
192 unsigned int Retries
;
195 // Queue the next available file for download.
200 // Specialized action members
201 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
202 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
203 pkgAcquire::MethodConfig
*Cnf
);
204 virtual string
MD5Sum() {return MD5
;};
205 virtual string
DescURI() {return Desc
.URI
;};
206 virtual string
ShortDesc() {return Desc
.ShortDesc
;};
207 virtual void Finished();
208 virtual bool IsTrusted();
210 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
211 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
212 string
&StoreFilename
);
215 // Fetch a generic file to the current directory
216 class pkgAcqFile
: public pkgAcquire::Item
218 pkgAcquire::ItemDesc Desc
;
220 unsigned int Retries
;
224 // Specialized action members
225 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
226 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
227 pkgAcquire::MethodConfig
*Cnf
);
228 virtual string
MD5Sum() {return Md5Hash
;};
229 virtual string
DescURI() {return Desc
.URI
;};
231 // If DestFilename is empty, download to DestDir/<basename> if
232 // DestDir is non-empty, $CWD/<basename> otherwise. If
233 // DestFilename is NOT empty, DestDir is ignored and DestFilename
234 // is the absolute name to which the file should be downloaded.
235 pkgAcqFile(pkgAcquire
*Owner
, string URI
, string MD5
, unsigned long Size
,
236 string Desc
, string ShortDesc
,
237 const string
&DestDir
="", const string
&DestFilename
="");