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 Three item classes are provided to provide functionality for
13 downloading of Index, Translation and Packages files.
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 class for index files
86 class pkgAcqIndex
: public pkgAcquire::Item
92 pkgAcquire::ItemDesc Desc
;
95 string CompressionExtension
;
99 // Specialized action members
100 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
101 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
102 pkgAcquire::MethodConfig
*Cnf
);
103 virtual string
Custom600Headers();
104 virtual string
DescURI() {return RealURI
+ CompressionExtension
;};
106 pkgAcqIndex(pkgAcquire
*Owner
,string URI
,string URIDesc
,
107 string ShortDesct
, string ExpectedMD5
, string compressExt
="");
110 // Item class for translated package index files
111 class pkgAcqIndexTrans
: public pkgAcqIndex
115 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
116 pkgAcqIndexTrans(pkgAcquire
*Owner
,string URI
,string URIDesc
,
128 // Item class for index signatures
129 class pkgAcqMetaSig
: public pkgAcquire::Item
133 pkgAcquire::ItemDesc Desc
;
134 string RealURI
,MetaIndexURI
,MetaIndexURIDesc
,MetaIndexShortDesc
;
135 indexRecords
* MetaIndexParser
;
136 const vector
<struct IndexTarget
*>* IndexTargets
;
140 // Specialized action members
141 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
142 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
143 pkgAcquire::MethodConfig
*Cnf
);
144 virtual string
Custom600Headers();
145 virtual string
DescURI() {return RealURI
; };
147 pkgAcqMetaSig(pkgAcquire
*Owner
,string URI
,string URIDesc
, string ShortDesc
,
148 string MetaIndexURI
, string MetaIndexURIDesc
, string MetaIndexShortDesc
,
149 const vector
<struct IndexTarget
*>* IndexTargets
,
150 indexRecords
* MetaIndexParser
);
153 // Item class for index signatures
154 class pkgAcqMetaIndex
: public pkgAcquire::Item
158 pkgAcquire::ItemDesc Desc
;
159 string RealURI
; // FIXME: is this redundant w/ Desc.URI?
161 const vector
<struct IndexTarget
*>* IndexTargets
;
162 indexRecords
* MetaIndexParser
;
166 void RetrievalDone(string Message
);
167 void AuthDone(string Message
);
168 void QueueIndexes(bool verify
);
172 // Specialized action members
173 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
174 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
175 pkgAcquire::MethodConfig
*Cnf
);
176 virtual string
Custom600Headers();
177 virtual string
DescURI() {return RealURI
; };
179 pkgAcqMetaIndex(pkgAcquire
*Owner
,
180 string URI
,string URIDesc
, string ShortDesc
,
182 const vector
<struct IndexTarget
*>* IndexTargets
,
183 indexRecords
* MetaIndexParser
);
186 // Item class for archive files
187 class pkgAcqArchive
: public pkgAcquire::Item
191 // State information for the retry mechanism
192 pkgCache::VerIterator Version
;
193 pkgAcquire::ItemDesc Desc
;
194 pkgSourceList
*Sources
;
197 string
&StoreFilename
;
198 pkgCache::VerFileIterator Vf
;
199 unsigned int Retries
;
202 // Queue the next available file for download.
207 // Specialized action members
208 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
209 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
210 pkgAcquire::MethodConfig
*Cnf
);
211 virtual string
MD5Sum() {return MD5
;};
212 virtual string
DescURI() {return Desc
.URI
;};
213 virtual string
ShortDesc() {return Desc
.ShortDesc
;};
214 virtual void Finished();
215 virtual bool IsTrusted();
217 pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
218 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
219 string
&StoreFilename
);
222 // Fetch a generic file to the current directory
223 class pkgAcqFile
: public pkgAcquire::Item
225 pkgAcquire::ItemDesc Desc
;
227 unsigned int Retries
;
231 // Specialized action members
232 virtual void Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
);
233 virtual void Done(string Message
,unsigned long Size
,string Md5Hash
,
234 pkgAcquire::MethodConfig
*Cnf
);
235 virtual string
MD5Sum() {return Md5Hash
;};
236 virtual string
DescURI() {return Desc
.URI
;};
238 pkgAcqFile(pkgAcquire
*Owner
,string URI
,string MD5
,unsigned long Size
,
239 string Desc
,string ShortDesc
);